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
Ashish_Mathur
Super User
6 years agoHi,
Is it fair to say that everytime there is a Y in the banked column, we should sum the figures in the fees column of the 3 months ended the date of the current row
Anonymous
6 years agoNot applicable
Hi Ashish_Mathur Yes that's correct but it can be for any amount of months.
v-kelly-msft I tried a variation of this before you posted also but get the following result:
As you can see I get the wrong total - the last value should be 3 595 699 and not 1 453 554.