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
sebbyp
Helper III
Helper III

Quick measure to calculate the difference from previous date

Capture.PNG

 

My datatable is organised as in the image above and i would like to calculate for each country the difference from the previous date.  How is this possible to do?

1 ACCEPTED SOLUTION
v-caliao-msft
Employee
Employee

@sebbyp,

 

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

Rank =
RANKX (
    FILTER ( Table1, Table1[Country] = EARLIER ( Table1[Country] ) ),
    Table1[Date],
    ,
    ASC
)
PreviousScore =
LOOKUPVALUE (
    Table1[Score],
    Table1[Country], Table1[Country],
    Table1[Rank], Table1[Rank] - 1
)

Capture.PNG

 

Regards,

Charlie Liao 

View solution in original post

2 REPLIES 2
v-caliao-msft
Employee
Employee

@sebbyp,

 

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

Rank =
RANKX (
    FILTER ( Table1, Table1[Country] = EARLIER ( Table1[Country] ) ),
    Table1[Date],
    ,
    ASC
)
PreviousScore =
LOOKUPVALUE (
    Table1[Score],
    Table1[Country], Table1[Country],
    Table1[Rank], Table1[Rank] - 1
)

Capture.PNG

 

Regards,

Charlie Liao 

@v-caliao-msftthank you so much for your help.  It worked perfectly and is so awesome.

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.

Top Solution Authors
Top Kudoed Authors