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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Minkee
Regular Visitor

Calculation for highest date for same ID value

Hi,

I am developing a report in PowerBI Desktop.

 

When a value in the column ID is shown multiple times I want the last column to contain a '1' for the row with the highest enddate.

 

IDStartdateEnddateColumn value
11-5-201831-12-20190
21-1-202431-12-20241
21-1-202331-12-20230
31-1-2024 0

 

Been struggling with all kinds of formula's but haven't been able to find a solution.

1 ACCEPTED SOLUTION
barritown
Super User
Super User

Hi @Minkee,

You can try such a calculated column:

barritown_0-1706817824780.png

DAX code in plain text for convenience:

Flag = 
VAR currentID = [ID]
VAR _tbl = FILTER ( Data, [ID] = currentID )
VAR maxDate = IF ( COUNTROWS ( _tbl ) > 1, MAXX ( _tbl, [Enddate] ) )
RETURN IF ( [Enddate] = maxDate && COUNTROWS ( _tbl ) > 1, 1, 0 )

 

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

View solution in original post

2 REPLIES 2
barritown
Super User
Super User

Hi @Minkee,

You can try such a calculated column:

barritown_0-1706817824780.png

DAX code in plain text for convenience:

Flag = 
VAR currentID = [ID]
VAR _tbl = FILTER ( Data, [ID] = currentID )
VAR maxDate = IF ( COUNTROWS ( _tbl ) > 1, MAXX ( _tbl, [Enddate] ) )
RETURN IF ( [Enddate] = maxDate && COUNTROWS ( _tbl ) > 1, 1, 0 )

 

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

Hi @barritown,

 

Many thanks for your help, much appreciated!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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