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

DAX Calculation for Dates

Hi, I have a datasource that updates at a regular basis, 

 

is there a way to categorize them, for either "Current" or "Previous" then the rest will be NULL.

 

Current means Latest update

Previous means previous update

 

The rest will show null as we only want to show current update and previous update

 

Goal (Tableau Reference):

 

Laedays_0-1623932303509.png

 

 

Goal:

 

LAST_UPDATE_DATEDAX calc
6/15/20201 2:14:34 AMnull
6/15/20201 9:42:25 AMPrevious
6/15/20201 6:34:25 PMCurrent 

 

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @Anonymous ,

 

You can create the following measure

Week = var _rank=RANKX(ALL('Table'),CALCULATE(MAX('Table'[Last Update Date])),,DESC,Dense)
return IF(_rank=1,"Current Week",IF(_rank=2,"Previous Week","Null"))

8.png

If you only want to keep three rows, write a metric to keep the first three rows.

Measure = var _rank=RANKX(ALL('Table'),CALCULATE(MAX('Table'[Last Update Date])),,DESC,Dense)
return IF(_rank<=3,1)

9.png

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-stephen-msft
Community Support
Community Support

Hi @Anonymous ,

 

You can create the following measure

Week = var _rank=RANKX(ALL('Table'),CALCULATE(MAX('Table'[Last Update Date])),,DESC,Dense)
return IF(_rank=1,"Current Week",IF(_rank=2,"Previous Week","Null"))

8.png

If you only want to keep three rows, write a metric to keep the first three rows.

Measure = var _rank=RANKX(ALL('Table'),CALCULATE(MAX('Table'[Last Update Date])),,DESC,Dense)
return IF(_rank<=3,1)

9.png

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

I found a solution that might help you.

I changed the datatype for the date column to date and I added a custom column with an if statement:

 

IF('Table'[Date]=max('Table'[Date]),"CURRENT","OLDER")

 

 

I get the following results in a table:

 

jacobs_0-1623931442743.png

 

Hope it helps.

Anonymous
Not applicable

Hi, thanks for your suggestion.

 

However, i only want to have 1 older and 1 current, the history should be null.

 

It's gonna update weekly, this is an example

 

Laedays_0-1623932265915.png

 

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.