how to calculate sum of an average field in crystal report - crystal-reports-2008

I have a field that calculates an average per row (Avg_Amt), it gives a correct output. My problem is how can I calculate the total summary of the average field (Avg Amt) then place it to the report footer.
Thanks & Best Regards.

Create 2 formula fields one for average and one for sum and insert this formula the first one
formula = Average ({Feild Name})
in the second formula from the report fields drag and drop the average formula and add the sum operation like :
formula = SUM({#Average})

If it is a straight average, use the sum wizard to add a sum for each field, then insert a formula field see below, this will actually get you to the accurate basis points average
(Sum ({#Field_1})/Sum ({#Field_2}))*100

Related

Trying to get correct grand totals for my measures

I'm calculating margin impact and the grand total is not the sum of the column. Below is the calculation measure:
=([CY_MARGIN]-[PY_MARGIN])*SUM(CYPY[CY_VOL])
I've tried adding sumx(values( to the calculation but I'm still not getting the correct column sum..

How to calculate the ratio between the grand total of two metrics on Google Data Studio?

I created a table on Data Studio that shows the columns:
A: Date
B: 1st metric (number)
C: 2nd metric (number)
D: custom formula to calculate the ratio between the 1st and 2nd metric (percentage)
Then I checked the option to show the Summary Row that sums all the values of each date. But in the column D I don't want it to calculate the sum of the values in column D (nor the average of the values), instead, I want the ratio between the sum of the values of column D and C. How to achieve that?
To have the calculated field correctly in the total, you have to make sure to aggregate your calculated field. To do so, use 'sum()' in your calculation.
That would be this formula:
sum(total sales)/sum(gross sales)
I hope this answers your question!

Different behavior of DAX measures depending on nesting

I wanted to calculate the median of the total sales for each category.
If I create the following two measures, it works perfectly:
SoS := SUM(Table1[Sales])
Median Category Sales :=
MEDIANX(
CALCULATETABLE(VALUES(Table1[Category]), ALL(Table1)),
[SoS]
)
However, If I don't nest the measures the median is not calculated and it returns just the sum.
Median without measure :=
MEDIANX(
CALCULATETABLE(VALUES(Table1[Category]), ALL(Table1)),
SUM(Table1[Sales])
)
See results below:
Why this happens? I thought the two approaches were exactly the same.
Actually, the first approach is equivalent to the following:
Median Category Sales :=
MEDIANX(
CALCULATETABLE(VALUES(Table1[Category]), ALL(Table1)),
CALCULATE(SUM(Table1[Sales]))
)
The SoS measure implicitly wraps its formula in a CALCULATE which causes a context transition for each Category provided through VALUES, thereby correctly calculating the sume of sales and therefore the median.

Average subset of time series in real time

Suppose there is a real time feed of stock prices, how do you calculate the average of a subset of it (say over the past week)?
This was an interview question. I can come up with an algorithm to do it in O(n^2), but the interviewer wanted an algorithm that was O(n).
A useful approach is to compute the cumulative sum of your array.
This means that each entry in the cumulative sum array is the sum of all previous prices.
This is useful because you can then generate the sum over any particular subarray of your input using a single subtraction.
Note that when a new input arrives, you only need 1 addition to compute the new cumulative sum (because you simply add the new element to the old cumulative sum).
Another approach is akin to computing skew in Genomics.
If you want to compute the average over the past week, create a variable that contains the sum over a moving window. When an entry is created, add the entry to the above sum variable, and subtract the oldest entry in the moving window from it. Since the size of the window is constant, the average over the past week is just the moving sum over the number of entries in the past week.

Formula workshop - formula editor in crystal report

I have something like this
quantuty 10,10,15,20,30
price per piece 2,2,5,7,4
I want to calculate total price for each row and sum all this
I use formula
Sum ({ESTIMATE_ITEMS.QUANTITY} * {ESTIMATE_ITEMS.PRICE_PER_PIECE} )
And I got an error mesage for this formula "A field is required here"
So what is wrong there?
Use a formula on each row that does the multiplication, then you can insert a summary summation on that formula field. In other words, take out the sum from your formula and save the formula, insert the formula as a field. Right click on the formula field and choose "insert summary" then choose "sum".

Resources