Forum Discussion
Anonymous
6 years agoNot applicable
Sum Values by condition for the previous months
Hi all I am trying to replicate this logic in Power BI. I have a column 'Fees' where I would like to sum the values in it when the condition 'Banked' is Yes (Y). But when the condition is met I w...
- Anonymous6 years ago
Here's a much simpler measure that works in all circumstances:
Measure = var __tableToIterateOver = filter( 'Table', 'Table'[BANKED] = "Y" ) var __amount = SUMX( __tableToIterateOver, var __currentDate = 'Table'[Date] var __result = calculate( var __prevDateOfBankedStatus = CALCULATE( MAX( 'Table'[Date] ), 'Table'[BANKED] = "Y", 'Table'[Date] < __currentDate ) var __output = CALCULATE( SUM( 'Table'[FEES] ), __prevDateOfBankedStatus < 'Table'[Date], 'Table'[Date] <= __currentDate ) return __output, // Leave only the filter on Fund. ALLEXCEPT( 'Table', 'Table'[Fund] ) ) return __result ) return __amountBest
D
Anonymous
6 years agoNot applicable
Ok this is my fault Anonymous I missed an "=" sign here:
Anonymous
6 years agoNot applicable
Looks like my previous post didn't go through Anonymous -
I missed the "=" sign in your posted measure:
Your measure does indeed give me the correct figures:
Thank you for all your help! Much appreciated
Fareed
- Anonymous6 years agoNot applicableNow you can immediately see how efficient it is to write CLEAR AND EASY TO UNDERSTAND measures. You would be able to identify any mistakes in no time and also make changes to the logic quite easily.
Compare this to the first measure you were served...
Best
D- Anonymous6 years agoNot applicable
Anonymous thanks I appreciate your input. I have been implementing similar concepts in writing my code.
v-kelly-msft also appreciate your input, thanks again.
Cheers,
Fareed