cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Fátima
Helper I
Helper I

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 I
Helper I

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
Power Participant
Power Participant

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!

 

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

BizApps LATAM 2023

Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

Power Platform Bootcamp

Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.