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 ,
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_val
If 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.