Is the following possible in DAX?
The following A,B,C,D,E ,..are maturity Buckets.A is a negative bucket , B is positive bucket
Bucket Amount
A -100
B 90
c -200
D 300
E -10
F 30
H -2
The requirement is to calculate the balance for each negative amount.The rule is positive amount can net negative amount in previous bucket , but not the next one. and this positive residual can flow to next available -ve bucket
so the formula for current negative bucket residual = ( previous negative bucket residual) + (SUm of previous positive bucket amounts up to previous negative bucket) + Current negative bucket amount
for A : -100 , the balance is 0 , as there is no positive amount in previous bucket
for C: -200 , the balance = (90 + -200) = -110, as this is a negative number it will not be used for next bucket
for E: -10 , the balance = (0) + 300-10 = 290 as the previous balance in c is negative and this needs to be treated as 0 or ignored.
for H : -2 , the balance = (290) + 30 - 2 = 318
I tried this in DAX using calculated columns using earlier function, but could not able to figure how to look up the previous computed value in the current computation.Its throwing circular dependency errors.
=IF(IF(D1>0,B2+D1,B2)>0,IF(D1>0,B2+D1,B2),0)
in D2, and copied it down the column (of course the cell references adjust during the copy, so in D3 I have=IF(IF(D2>0,B3+D2,B3)>0,IF(D2>0,B3+D2,B3),0)
. Anyhow...it is interesting. – Marc Pincince