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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Fátima
Helper II
Helper II

DAX help - Calculated boolean column with latest value of each ID

Hi!

 

I have a dataset that looks like this:

 

C_ID     DATE            

1           01/01/2022

2           02/01/2022

2           03/01/2022

3           04/01/2022

4           06/01/2022

4           05/01/2022

 

I need to create a calculated column that shows true if it's the latest of each ID, like this:

 

C_ID     DATE                   isTheLatestOfId

1           01/01/2022        True

2           02/01/2022        False

2           03/01/2022        True

3           04/01/2022        True

4           06/01/2022        True

4           05/01/2022        False

 

Is there a way I can do this with DAX?

 

So far I managed to obtain the latest of all of them like this:

isTheLatestOfId= IF(CALCULATE(MAX(T1[Date]))=MAX(T1[Date]),TRUE,FALSE)

 

But it only sets to true the one with date "06/08/2022 13:50".

 

Thank you in advance!!

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

Hi @Fátima 

You can refer to the following example.

You can create a column:

 

isTheLatestOfId = var _filter=FILTER('Table',[C _ID]=EARLIER('Table'[C _ID]))
return if([DATE]=MAXX(_filter,[DATE]),TRUE(),FALSE())

 

Or you can create it as a measure:

 

Measure = var _filter=FILTER(ALL('Table'),[C _ID]=MAX('Table'[C _ID]))
return IF(MAX([DATE])=MAXX(_filter,[DATE]),TRUE(),FALSE())

 

Output:

vxinruzhumsft_0-1674095859843.png

 

vxinruzhumsft_1-1674095867931.png

 

Best Regards!

Yolo Zhu

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
Fátima
Helper II
Helper II

Thank you @v-xinruzhu-msft and @olgad !

 

Since the answer by @v-xinruzhu-msft allows me to not create an additional column, I'll mark that one as the accepted solution.

 

Regards!

v-xinruzhu-msft
Community Support
Community Support

Hi @Fátima 

You can refer to the following example.

You can create a column:

 

isTheLatestOfId = var _filter=FILTER('Table',[C _ID]=EARLIER('Table'[C _ID]))
return if([DATE]=MAXX(_filter,[DATE]),TRUE(),FALSE())

 

Or you can create it as a measure:

 

Measure = var _filter=FILTER(ALL('Table'),[C _ID]=MAX('Table'[C _ID]))
return IF(MAX([DATE])=MAXX(_filter,[DATE]),TRUE(),FALSE())

 

Output:

vxinruzhumsft_0-1674095859843.png

 

vxinruzhumsft_1-1674095867931.png

 

Best Regards!

Yolo Zhu

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

 

olgad
Super User
Super User

Hi Fatima, 
not dax, but may be you can use it.
In Power query go transform group by 

olgad_2-1674061979449.png

 

olgad_3-1674062012224.pngolgad_4-1674062086600.png

olgad_5-1674062105397.png

Hope that helps you!

 


DID I ANSWER YOUR QUESTION? PLEASE MARK MY POST AS A SOLUTION! APPRECIATE YOUR KUDO/LIKE!
PROUD TO BE A SUPER USER!
Best Stories, Interesting Cases: PowerBI Storytime Newsletter
Linkedin Profile: Linkedin
YouTube Channel: PowerBI Storytime

Helpful resources

Announcements
March Fabric Community Update

Fabric Community Update - March 2024

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

Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.