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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
bleow
Frequent Visitor

Selecting max value for each row with the same condition

I have the following data:

 

IDDate
014/5/2020
01null
021/6/2021
032/3/2021

 

I want to create a second column Date2 that states the max date for each ID, like so:

 

IDDateDate2
014/5/2020null
011/1/9999null
021/6/20211/6/2021
032/3/20212/3/2021

 

Is there a solution for this that doesn't involve Group By? To elaborate, my current method for doing this is:

  1. Replace null with a date far far into the future, e.g. 1/1/9999
  2. Duplicate the data table
  3. Group the duplicate table by max of Date to get Date2, which will ensure 1/1/9999 is selected should it exist for each Misc Value
    1. Screenshot 2021-06-10 190624.png
  4. Merge the original with the duplicate
    1. Screenshot 2021-06-10 190819.png
  5. Replace 1/1/9999 back with null

But I'm not really a fan of this rudimentary technique because it involves so many steps. Does a simpler, formula-based solution exist?

 

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@bleow,

 

Try this calculated column (DAX):

 

Date2 = 
VAR vMaxDateNoBlank =
    CALCULATE ( MAX ( Table1[Date] ), ALLEXCEPT ( Table1, Table1[ID] ) )
VAR vRowCountWithBlank =
    CALCULATE (
        COUNTROWS ( Table1 ),
        ALLEXCEPT ( Table1, Table1[ID] ),
        ISBLANK ( Table1[Date] )
    )
VAR vResult =
    IF ( vRowCountWithBlank > 0, BLANK (), vMaxDateNoBlank )
RETURN
    vResult

 

DataInsights_0-1623502887253.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @bleow ,

You can create a measure as below to get it:

Date2 = 
VAR _count =
    COUNTX (
        FILTER (
            ALLSELECTED(  'Table' ),
            'Table'[ID] = SELECTEDVALUE ( 'Table'[ID] )
                && ISBLANK ( 'Table'[Date] )
        ),
        [ID]
    )
RETURN
    IF (
        _count > 0,
        BLANK (),
        CALCULATE ( MAX ( 'Table'[Date] ), ALLEXCEPT ( 'Table', 'Table'[ID] ) )
    )

yingyinr_2-1623724036050.png

Best Regards

DataInsights
Super User
Super User

@bleow,

 

Try this calculated column (DAX):

 

Date2 = 
VAR vMaxDateNoBlank =
    CALCULATE ( MAX ( Table1[Date] ), ALLEXCEPT ( Table1, Table1[ID] ) )
VAR vRowCountWithBlank =
    CALCULATE (
        COUNTROWS ( Table1 ),
        ALLEXCEPT ( Table1, Table1[ID] ),
        ISBLANK ( Table1[Date] )
    )
VAR vResult =
    IF ( vRowCountWithBlank > 0, BLANK (), vMaxDateNoBlank )
RETURN
    vResult

 

DataInsights_0-1623502887253.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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