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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Show only most recent row for each ID

I have a table that follows this structure

ID_ClassDate of conclusion
1111-Class A   13/04/2022
1111-Class B20/04/2022
2222-Class A26/07/2022
2222-Class A30/09/2022
2222-Class B14/02/2022
3333-Class A20/03/2022

The ID_Class column combines the person's unique id and the name of the class they attended. But sometimes there are people who do the same class twice or more but on different dates.
I wanted to create a column of TRUE and FALSE that would bring me the TRUE value whenever each distinct ID_Class is the most recent (since I want to fetch only the most recent courses taken by each person. If a person took the same course twice, I want to see only the most recent of these two courses).


The expected result would be something like this:

ID_ClassDate of conclusion Most_Recent
1111-Class A   13/04/2022TRUE
1111-Class B20/04/2022TRUE
2222-Class A26/07/2022FALSE
2222-Class A30/09/2022TRUE
2222-Class B14/02/2022TRUE
3333-Class A20/03/2022TRUE
3333-Class A22/01/2022FALSE



How can I do this?

1 ACCEPTED SOLUTION
smpa01
Super User
Super User

@Anonymous  you need a measure like following

smpa01_0-1675276539482.png

Measure = 
VAR dt =
    MAX ( 'fact'[dt] )
VAR mxDt =
    CALCULATE ( MAX ( 'fact'[dt] ), ALLEXCEPT ( 'fact', 'fact'[ID_Class] ) )
RETURN
    SWITCH ( TRUE (), dt = mxDt, TRUE (), FALSE () )

 

@Sahir_Maharaj  DAX rule of thumb,  don't create calculated columns if you can create a measure

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

5 REPLIES 5
smpa01
Super User
Super User

@Anonymous  you need a measure like following

smpa01_0-1675276539482.png

Measure = 
VAR dt =
    MAX ( 'fact'[dt] )
VAR mxDt =
    CALCULATE ( MAX ( 'fact'[dt] ), ALLEXCEPT ( 'fact', 'fact'[ID_Class] ) )
RETURN
    SWITCH ( TRUE (), dt = mxDt, TRUE (), FALSE () )

 

@Sahir_Maharaj  DAX rule of thumb,  don't create calculated columns if you can create a measure

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Sahir_Maharaj
Super User
Super User

Hi @Anonymous,

 

Yes, you're correct. The [Date of conclusion] column should be a column in your table, not a measure. In a DAX formula for a calculated column, you can reference other columns in the same table, but you can't reference measures.

 

So, in this case, you need to make sure that the [Date of conclusion] column is a column in your table and not a measure. Then, you can reference it in your DAX formula to compare the date of conclusion for the current row with the date of conclusion for other rows with the same ID_Class.

 

Let me know if this works.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ About: https://sahirmaharaj.com/about.html
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning
Sahir_Maharaj
Super User
Super User

This formula uses a calculated column that creates a variable CurrentIDClass that stores the value of the ID_Class column for the current row. Then, it returns TRUE if the date of conclusion for the current row is equal to the minimum date of conclusion for all rows with the same ID_Class. Otherwise, it returns FALSE.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ About: https://sahirmaharaj.com/about.html
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning
Sahir_Maharaj
Super User
Super User

You can use the following DAX formula to achieve the desired result:

 

Most_Recent = VAR CurrentIDClass = MIN('Table'[ID_Class]) RETURN IF(CurrentIDClass = MIN(FILTER('Table', 'Table'[ID_Class] = MIN('Table'[ID_Class]))[Date of conclusion]), TRUE, FALSE)

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ About: https://sahirmaharaj.com/about.html
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning
Anonymous
Not applicable

Hi, @Sahir_Maharaj  Thanks for the quick response! 🙂

I didn't quite understand the

[Date of conclusion]

part in your code. Does it use a measure for the date of conclusion? Because when I try to do it here, I can't pull the "Date of conclusion" column of my table, it only lets me bring measures.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors