Forum Discussion
Using SUM in a Calculated Column returns unexpected results
- 8 years ago
Under visualization pane in the values Click on the "ratio" column and click on the last value "show value as" and click percent of grand total.
This should give you the desired result.
Thanks
I add the Calculated Column Ratio = DIVIDE(Regions[Revenue],sum(Regions[Revenue]),0). The result is above. It still has the same effect,I.e., dividing by the entire sum rather than just the sum for Asia which should be 600.
Thanks.
Under visualization pane in the values Click on the "ratio" column and click on the last value "show value as" and click percent of grand total.
This should give you the desired result.
Thanks
- Anonymous8 years agoNot applicable
Thank you, that does work indeed. So to summarize, I have two Calculated Columns as follows:
Total_Revenue_Col = sum(Regions[Revenue])
Ratio = DIVIDE(Regions[Revenue],Regions[Total_Revenue_Col],0)
for 'Ratio' I switch 'Show value as' to 'Percent of grand total' and this is my final result:
So here although Total_Revenue_Col is showing 1600, the Ratio is actually dividing 100/600 where 600 is the total of Asia.
So I have also created a new Measure as follows:
Total_Revenue_Me = CALCULATE(sum(Regions[Revenue]),all(Regions[Country]))
Because CALCULATE triggers context transition (I.e., Row Context becomes Filter Context) I apply the ALL command on the Country so that it does not become part of the Filter Context (otherwise the total will just be equal to the Revenue on that row).
So now this is what I have:
Now I can see the 600 properly showing up. But keep in mind the Raio is not dividing on Total_Revenue_Me.
What I still find perplexing is why I didn't get this same effect for the Total_Revenue_Col?
In the book 'The Definitive Guid to DAX' I read that when SUM is used in a Calculated Column, the formula will compute the sum of all values in the current filter context and in the case above the 'current filter context' will be Asia.
- sqlguru4487 years agoHelper III
Even if there is a row context, SUM ignoes it. Instead, it uses the filter context and the filter context is full set of row. You will get thegrand total o revenue and same value for all rows. check 4-7 in the book you are trying to refer. (Definitive guide to DAX)
Try using SUMX since it creates an iterator which will evaluate row by row.