Forum Discussion

ddata's avatar
ddata
New Member
9 years ago
Solved

DAX: sum with fslicers

Hi, I have 3 columns: Country, Company and  Amount. When I use slicers on Country and Company, I need to get sum of  the amount for all the companies excluding the selected company in the selected c...
  • Anonymous's avatar
    Anonymous
    9 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.