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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

DAX Show Value based on latest date with multiple filters

I'm fairly novice in DAX and need help with the following forumla:

What i need is a measure that will display the latest (most recent date) hours for a specific unit and type:

If i wanted Unit 1 Type A, i would want it to display 1200 (this is the hours from the most recent entry)

MAX function will not work as the hours can be higher on ealier dates so i need the latest hours from the date/time

 

Date/TimeUnitTypeHours
01/01/2020 1:00Unit 1A1000
01/02/2020 8:00Unit 2B500
01/10/2020 10:00Unit 1A1100
01/11/2020 8:00Unit 2A600
01/12/2020 8:00Unit 1A1200
2 REPLIES 2
v-shex-msft
Community Support
Community Support

HI @Anonymous,

You can use the following measure formula to get lastest hours based on the current unit and type group:

 

Lastest Hour =
VAR filtered =
    CALCULATETABLE (
        t3,
        ALLSELECTED ( t3 ),
        VALUES ( T3[Unit] ),
        VALUES ( T3[Type] )
    )
VAR _max =
    MAXX ( filtered, [Date/Time] )
RETURN
    MAXX ( FILTER ( filtered, [Date/Time] = _max ), [Hours] )

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
amitchandak
Super User
Super User

@Anonymous 

Try

 

VAR __id = MAX ( 'Table'[id] )
VAR __Type = MAX ( 'Table'[Type] )

VAR __date = CALCULATE ( MAX( 'Table'[date] ), ALLSELECTED ( 'Table' ),  'Table'[id] = __id,'Table'[Type] = __Type  ) 
RETURN CALCULATE ( MAX ( 'Table'[value] ), VALUES ( 'Table'[id] ), 'Table'[id] = __id,'Table'[Type] = __Type , 'Table'[date] = __date )

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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