Forum Discussion
DAX previous row value in calculation
PKPK90 , You can create a calculated column for Norm using below dax
NORM =
VAR CurrentIndex = 'Table'[Index]
VAR CurrentEXP = 'Table'[EXP]
VAR PreviousNORM =
CALCULATE(
MAX('Table'[NORM]),
FILTER(
'Table',
'Table'[SiteItem] = EARLIER('Table'[SiteItem]) &&
'Table'[Index] < CurrentIndex
)
)
VAR OutstandingReceipt = 'Table'[OutstandingReceipt]
VAR OutStandingRequirement = 'Table'[OutStandingRequirement]
VAR OnHandQtyADJ =
CALCULATE(
SUM('Table'[OnHandQtyADJ]),
FILTER('Table', 'Table'[Ref_OrderNo.1] = "BALANCE")
)
VAR SafetyStockADJ =
CALCULATE(
SUM('Table'[SafetyStockADJ]),
FILTER('Table', 'Table'[Ref_OrderNo.1] = "BALANCE")
)
VAR Calculation = OutstandingReceipt - OutStandingRequirement + OnHandQtyADJ - SafetyStockADJ
VAR Result =
IF(
CurrentEXP = 1,
IF(
PreviousNORM < 0,
PreviousNORM,
IF(
PreviousNORM > 0,
MAX(0, PreviousNORM + Calculation),
PreviousNORM + Calculation
)
),
PreviousNORM + Calculation
)
RETURN
Result
Hi, thank you for your reply. In your message, you are referring to the NORM column, which is just an example of what I hope to achieve with the DAX calculation. The NORM column should not be included in the calculation.
- Anonymous2 years agoNot applicable
Hi bhanu_gautam ,thanks for the quick reply, I'll add more.
Hi PKPK90 ,
Regarding your question, I think DAX cannot meet your needs, you need to use Power Query to do iterative calculations.
Best Regards,
Wenbin Zhou