Forum Discussion
DAX: sum with fslicers
- Anonymous9 years ago
OK, I've tested it and as far as I can tell it works fine even if only one slicer has a selection. So that's good news. In testing this, I realized there's a much simpler way to get the same result. Take the sum of all Amount and subtract whatever you have selected. Not by subtracting table rows but by subtracting simple sums.
Sum of Amount Not Selected = CALCULATE( SUM(TableName[Amount]), ALL(TableName) ) - SUM(TableName[Amount])
This does suffer the same problem as before; if nothing is selected in either slicer the result is 0. So we can use the same trick as before to get a regular sum in those cases:
Sum of Amount Not Selected = IF( COUNTROWS(ALL(TableName)) - COUNTROWS(ALLSELECTED(TableName)) = 0, SUM(TableName[Amount]), CALCULATE( SUM(TableName[Amount]), ALL(TableName) ) - SUM(TableName[Amount]) )
I think this solution is about 10x less cool than my first idea, but it does have the advantage of being easier to wrap your head around. They both give the same results, so you can use whichever one you like.
Hi ddata,
Please try this:
Sum for unselected Company = CALCULATE ( SUM ( 'Test Table'[Amount] ), ALLEXCEPT ( 'Test Table', 'Test Table'[Country] ) ) - CALCULATE ( SUM ( 'Test Table'[Amount] ) )
Best regards,
Yuliana Gu