Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Use DAX and M-Query to get the previous row values into new column.

Hai All,

 

Question: Need solution in both M-QUERY and DAX to get the previous row value into a new column.

 

The below table represents a sample data representing the price for the corresponding Dates.

Pcd-Price for current date

ppdr-Price for previous date reference.

ppd-price for previous date

 

 

 

saimahesh_0-1620829691436.png

 

Here we considered the data which is from date 10 to 19(refer above table).

 

 For Example

If we consider date '19' in 1st row.... pcd column 1st row should have 19 date pcd value and new ppd column should have 18 date pcd value in !st row  (Check the arrow marks in the above data)
 
Case: If each and every row goes one row up, then we may find the last row in newly created column(ppd) as BLANK/Null then in that place we need to replace it with the previous date(9) pcd value.
 
Note:
--> The newly created column(PPD) should be equal to PPDR column ( Do not use PPDR ,It is only for reference purpose)
-->Please provide solution in M-QUERY and DAX
 
Thanks in advance. Expecting earlier solution for this.
1 ACCEPTED SOLUTION
Vera_33
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

If you column [S.No] is like Index, use this column, otherwise add an index column, M here

 

Vera_33_0-1620869361314.png

 

Table.AddColumn(#"Changed Type", "ppd_M", each #"Changed Type"[pcd]{[S.No]}?)

 

DAX here

Vera_33_1-1620869389830.png

ppd_DAX = 
VAR CurNo = 'Table'[S.No]
RETURN
CALCULATE(VALUES('Table'[pcd]),FILTER(ALL('Table'),'Table'[S.No]=CurNo+1))

View solution in original post

1 REPLY 1
Vera_33
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

If you column [S.No] is like Index, use this column, otherwise add an index column, M here

 

Vera_33_0-1620869361314.png

 

Table.AddColumn(#"Changed Type", "ppd_M", each #"Changed Type"[pcd]{[S.No]}?)

 

DAX here

Vera_33_1-1620869389830.png

ppd_DAX = 
VAR CurNo = 'Table'[S.No]
RETURN
CALCULATE(VALUES('Table'[pcd]),FILTER(ALL('Table'),'Table'[S.No]=CurNo+1))

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.