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
Anonymous
Not applicable

Help! A measure to compare the dates from two different columns.

Hello All,

TT1.PNG

 

I'm looking to compare the Start date of a row with the end date of the previous row using an if condition and display the result in a calculated column.

Here for example , if you take row 2 - I'm looking to compare Jan 10 with Feb 1.

Looking forward to your help.

 

Thanks.

 

 
1 ACCEPTED SOLUTION
kentyler
Solution Sage
Solution Sage

Getting a value from the previous row is not something that is native to Power BI. But it is a very common request.

We use a work around. Since we always want just the previous row we add an index to our table (this assumes the table arrives in power bi in the proper sort order).

addindex.png

Once we have an index we can use it to "move back" to the previous row and get the date

Previous Start Date =
var cur_index = Dates[Index]
// Since we always want to move to the previous row
var prev_index = Dates[Index] - 1

// We ask for ALL() of the table, and then filter for the row that has the matching index
var prev_start_date = calculate(MAX(Dates[Start Date]),ALL(dates),Dates[Index] = prev_index)

//if there was no previous row, we get a blank
return prev_start_date
prevStartDate.png




Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


View solution in original post

2 REPLIES 2
kentyler
Solution Sage
Solution Sage

Getting a value from the previous row is not something that is native to Power BI. But it is a very common request.

We use a work around. Since we always want just the previous row we add an index to our table (this assumes the table arrives in power bi in the proper sort order).

addindex.png

Once we have an index we can use it to "move back" to the previous row and get the date

Previous Start Date =
var cur_index = Dates[Index]
// Since we always want to move to the previous row
var prev_index = Dates[Index] - 1

// We ask for ALL() of the table, and then filter for the row that has the matching index
var prev_start_date = calculate(MAX(Dates[Start Date]),ALL(dates),Dates[Index] = prev_index)

//if there was no previous row, we get a blank
return prev_start_date
prevStartDate.png




Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Anonymous
Not applicable

Thanks for your reply! I will work with index column.

 

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.