Forum Discussion
Previous rows value based on date (Lag functionality from SQL in Power BI logic)
- 4 years ago
Hi Anonymous ,
You can try formula like below:
M_Pre = VAR pre_ = CALCULATE ( MAX ( 'Table'[Date] ), FILTER ( ALL ( 'Table' ), 'Table'[Date] <= MAX ( 'Table'[Date] ) - 1 ) ) RETURN CALCULATE ( MAX ( 'Table'[Volumn] ), FILTER ( ALL ( 'Table' ), 'Table'[Date] = pre_ ) )If converted into a calculated column formula, you can use the top function to get the value of any of the first few lines (or summation). Specific reference to the following formula:
Column = VAR pre_row = TOPN ( 1, FILTER ( 'Table', 'Table'[Month] < EARLIER ( 'Table'[Month] ) && 'Table'[Employee] = EARLIER ( 'Table'[Employee] ) ), [Month], DESC ) VAR pre_val = MINX ( pre_row, [Sales] ) RETURN 'Table'[Sales] + pre_valIf the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.
Best Regards,
Henry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous
Is [Cumulative_Inv] a measure or a calculated column? Are trying to create a measure or a calculated column?
- Anonymous4 years agoNot applicable
I am trying to create a measure . Cumulative_Inv is also a measure.
- tamerj14 years agoCommunity Champion
Anonymous
Ok, I will modify the code once I reach home.
- tamerj14 years agoCommunity Champion
Anonymous
Here is the updated sample file https://www.dropbox.com/t/sksZWPPXQ5uJlEMqBeginning_Inv = VAR CurrentDate = MAX ( Short_Ship[Planned_Dates] ) VAR PlantMaterialTable = CALCULATETABLE ( Short_Ship, ALLEXCEPT ( Short_Ship,Short_Ship[Plant], Short_Ship[Material_ID] ) ) VAR FilteredTable = FILTER ( PlantMaterialTable, Short_Ship[Planned_Dates] < CurrentDate ) VAR PreviousDate = MAXX ( FilteredTable, Short_Ship[Planned_Dates] ) RETURN CALCULATE ( [Cumulative_Inv], Short_Ship[Planned_Dates] = PreviousDate, PlantMaterialTable )