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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors