Forum Discussion
Dynamic measures( Sum and Difference) for based on Slicer selection
- Anonymous5 years ago
Hi kkalyanrr ,
Please try this measure after adding a new table for slicer:
Measure = VAR _all = ALLSELECTED ( forSlicer[Type] ) VAR countSele = COUNTROWS ( FILTER ( 'forSlicer', 'forSlicer'[Type] IN _all ) ) VAR _income = CALCULATE ( SUM ( 'Table'[Amount] ), FILTER ( 'Table', 'Table'[CategoryName] = "Income" ) ) VAR _sum = CALCULATE ( SUM ( 'Table'[Amount] ), FILTER ( 'Table', 'Table'[CategoryName] IN _all ) ) RETURN IF ( countSele = 1 && "Income" IN _all, _income, IF ( countSele >= 2 && "Income" IN _all, _income * 2 - _sum, _sum ) )My final output looks like this : ( measure in the lower left corner is just for test)
Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.Best Regards,
Eyelyn Qin
kkalyanrr , Try a measure like.
measure =
var _1 = countx(filter(allselected(Table),Table[Category] ="Income"),Table[Category])
var _2 = countx(filter(allselected(Table),Table[Category] <> "Income"),Table[Category])
return
if(isblank(_1) || isblank(_2), Sum(Table[Amount]), calculate(sumx(Table, if(Table[Category] ="Income", Table[Amount],-1* Table[Amount]))))
Better to have a category an independent slicer