Forum Discussion
akhilduvvuru
Helper IV
1 year agoOpening and Closing balance recursive calculation
Team, I have a requirement where I have table with 3 fields 1. Value Date, 2. Actual Amount, 3. Flow Amount as mentioned below coming from backend Date Actual Amount Flow Amount 18/12/24...
- 1 year ago
Try it like this.
Fcst Amt = VAR _LastActual = CALCULATE ( LASTNONBLANK ( 'Table'[Date], CALCULATE ( SUM ( 'Table'[Actual] ) ) ), ALL ( 'Table' ) ) VAR _LastActualAmt = CALCULATE ( LASTNONBLANKVALUE ( 'Table'[Date], CALCULATE ( SUM ( 'Table'[Actual] ) ) ), ALL ( 'Table' ) ) VAR _RowDate = 'Table'[Date] RETURN IF ( _RowDate <= _LastActual, 'Table'[Actual], _LastActualAmt + CALCULATE ( SUM ( 'Table'[Flow] ), ALL ( 'Table' ), 'Table'[Date] > _LastActual, 'Table'[Date] <= _RowDate ) )
akhilduvvuru
Helper IV
1 year agoThanks jdbuchanan71 for your help. Small correction in the way data is present.
This is how the data looks like. Please help with the same.
Because, my data is in the above format, when I apply the logic which you suggested, I'm getting the following result.
jdbuchanan71
Super User
1 year agoTry it like this.
Fcst Amt =
VAR _LastActual =
CALCULATE (
LASTNONBLANK ( 'Table'[Date], CALCULATE ( SUM ( 'Table'[Actual] ) ) ),
ALL ( 'Table' )
)
VAR _LastActualAmt =
CALCULATE (
LASTNONBLANKVALUE ( 'Table'[Date], CALCULATE ( SUM ( 'Table'[Actual] ) ) ),
ALL ( 'Table' )
)
VAR _RowDate = 'Table'[Date]
RETURN
IF (
_RowDate <= _LastActual,
'Table'[Actual],
_LastActualAmt
+ CALCULATE (
SUM ( 'Table'[Flow] ),
ALL ( 'Table' ),
'Table'[Date] > _LastActual,
'Table'[Date] <= _RowDate
)
)