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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
eacy
Helper II
Helper II

DAX Adding offset to previous row

Hi,

 

I would like to create a column either in DAX or M where the some row are a date from another column and some are the previous row plus an offset, like:

 

IF(TABLE[INITIAL] = TRUE();
  TABLE[CREATED];
  DATEADD(TABLE[value from previous row];TABLE[OFFSET])
)

any suggestions are appriciated

 

1 ACCEPTED SOLUTION
v-caliao-msft
Employee
Employee

Hi @eacy,

 

Yes, we can achieve this requirement is Power BI by adding a calculated column. In your scenario, did you encounter any issue when using this formula?

 

In DAX you can’t reference the previous row in any way because there is no order to the rows, So fi you need to get previous row, you can create a rank column, and then use LOOKUPVALUE function to get it.

Rank = RANKX('TABLE','TABLE'[ID],,1)
Previous = LOOKUPVALUE('TABLE'[CREATED],'TABLE'[Rank],'TABLE'[Rank]-1)
Column = IF('TABLE'[INITIAL]=1,'TABLE'[CREATED],DATEADD('TABLE'[Previous],'TABLE'[OFFSET],DAY))

Capture.PNG

 

Reference

http://www.powerpivotpro.com/2015/03/how-to-compare-the-current-row-to-the-previous-row-in-power-piv...

 

Regards,

Charlie Liao

View solution in original post

2 REPLIES 2
v-caliao-msft
Employee
Employee

Hi @eacy,

 

Yes, we can achieve this requirement is Power BI by adding a calculated column. In your scenario, did you encounter any issue when using this formula?

 

In DAX you can’t reference the previous row in any way because there is no order to the rows, So fi you need to get previous row, you can create a rank column, and then use LOOKUPVALUE function to get it.

Rank = RANKX('TABLE','TABLE'[ID],,1)
Previous = LOOKUPVALUE('TABLE'[CREATED],'TABLE'[Rank],'TABLE'[Rank]-1)
Column = IF('TABLE'[INITIAL]=1,'TABLE'[CREATED],DATEADD('TABLE'[Previous],'TABLE'[OFFSET],DAY))

Capture.PNG

 

Reference

http://www.powerpivotpro.com/2015/03/how-to-compare-the-current-row-to-the-previous-row-in-power-piv...

 

Regards,

Charlie Liao

Hi Charlie Liao,

 

Thanks, this sound plausible, I will try to see if I can find the time to test this today.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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