Forum Discussion
incorrect Total Selected Value alternative
Hi,
I need to sum quanities differently depending on my column values. The working example is much more complex with info I cannot share so I have drafted up a basic example using the Table below.
In the measure, I simply Sum up the quantities, but where the type is a Donkey I add the quanitites from Cow's (VAR _A).
Table
Type Quantity
| Donkey | 5 |
| Donkey | 5 |
| Duck | 3 |
| Duck | 5 |
| Dog | 4 |
| Dog | 5 |
| Cow | 3 |
| Cow | 5 |
Everything works how I want it to except the total is incorrect as I am using selected value (I underdstand why). Can anyone please assist? I cannot use a calculated column in the real example.
Hi,
so, leave your first calculation like thisExample = VAR _A =CALCULATE(SUM('Example Table'[Quantity]),FILTER(ALL('Example Table'),'Example Table'[Type] = "Cow"))VAR _B =SUM('Example Table'[Quantity])
RETURNIF(SELECTEDVALUE('Example Table'[Type]) = "Dog" ||SELECTEDVALUE('Example Table'[Type]) = "Donkey",_B / _A,0)Add one more measure:
Example2 =
SUMX(SUMMARIZE('Example Table', 'Example Table'[Type], "Example Correct", 'Example Table'[Example]), [Example Correct])
8 Replies
- olgadResident Rockstar
Hi,
I dont know if it is gonna fit your real example,
but here it isExample = VAR _A =CALCULATE(SUM('Example Table'[Quantity]),FILTER(ALL('Example Table'),'Example Table'[Type] = "Cow"))VAR _B =SUM('Example Table'[Quantity])RETURNIf(HASONEVALUE('Example Table'[Type]), IF(SELECTEDVALUE('Example Table'[Type]) = "Donkey",_A + _B,_B),_B+_A)- NMOOREHelper II
Thanks so much Olgad, just away from my work at the moment I'll give it a whirl on Monday. Cheers
- NMOOREHelper II
Hi Olgad,
Thanks again for the above. It solves the issue listed but I didnt distill the complexity of my issue into the example very well.
I'm hoping this might be more in line with my issue. If we use the same measure but using your method of HASONEVALUE there are more cases which need to be involved.
Because I need to Filter ALL on some tables I cannot then make it sum properly. I've been trying to create seperate measures and Sum them just in a total but the SelectedValue always follows.
RETURNIF(HASONEVALUE('Example Table'[Type]),IF(SELECTEDVALUE('Example Table'[Type]) = "Dog" ||SELECTEDVALUE('Example Table'[Type]) = "Donkey",_B / _A,0),_B / _A)I hope I'm missing something obvious. Let me know if you get the chance?
Thanks
- olgadResident Rockstar
Hi,
so, leave your first calculation like thisExample = VAR _A =CALCULATE(SUM('Example Table'[Quantity]),FILTER(ALL('Example Table'),'Example Table'[Type] = "Cow"))VAR _B =SUM('Example Table'[Quantity])
RETURNIF(SELECTEDVALUE('Example Table'[Type]) = "Dog" ||SELECTEDVALUE('Example Table'[Type]) = "Donkey",_B / _A,0)Add one more measure:
Example2 =
SUMX(SUMMARIZE('Example Table', 'Example Table'[Type], "Example Correct", 'Example Table'[Example]), [Example Correct])