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,
To your visual, you should be dragging the Date column from the Calendar Table and remove the Planned_Dates column. Ensure there is a relationship (Many to One and Single) from the Planned_Dates column and Date column of the Calendar Table. Assuming Beg_Inv and Rec/Req_Quantities are measures, write this measure for computing Beginning_Inv
=[Beg_Inv]-calculate([Rec/Req_Quantities],datesbetween(calendar[date],minx(all(calendar[date]),calendar[date]),max(calendar[date])))