cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
RustyNails
Helper III
Helper III

DAX to return the corresponding value of a max date

Hi, I have a table that looks like this:

Order IDLink IDOrder DateOrder Status
10150166/17/2019Y
10250164/20/2022N
10350167/23/2018Y
11150145/5/2020N
11250141/4/2021Y

 

Each Link ID can have multiple Order ID's. What I'm trying to do is look up Orders based on the Link ID, and return the Max of Order Date, and that Max Order Date's corresponding Order Status. Like Below (Link Date and Link Status):

 

Order IDLink IDOrder DateOrder StatusLink DateLink Status
10150166/17/2019Y4/20/2022N
10250164/20/2022N4/20/2022N
10350167/23/2018Y4/20/2022N
11150145/5/2020N1/4/2021Y
11250141/4/2021Y1/4/2021

Y

 

I was able to work out the Link Date DAX formula, but I'm unable to fetch it's corresponding Link Status.


Link Date: 

 

 

 

 

 

CALCULATE(
    MAX(Table[Order Date]),
    FILTER((Table), Table[Link ID] = earlier(Table[Link ID]))
)

 

 

 

 

 

 

How do I get the corresponding Order Status for the Link Date?

Any help is appreciated.

Edit: I goofed up the formatting, but here's a clearer picture

 

RustyNails_0-1663603773880.png

 



1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@RustyNails Try:

Link Status =
VAR __LinkID = MAX(Table[Link ID])
VAR __LinkDate = 
CALCULATE(
    MAX(Table[Order Date]),
    FILTER((Table), Table[Link ID] = __LinkID )
)
RETURN
  MAXX(FILTER(ALL(Table),Table[Link ID] = __LinkID && Table[Order Date] = __LinkDate),[Link Status])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

@RustyNails Try:

Link Status =
VAR __LinkID = MAX(Table[Link ID])
VAR __LinkDate = 
CALCULATE(
    MAX(Table[Order Date]),
    FILTER((Table), Table[Link ID] = __LinkID )
)
RETURN
  MAXX(FILTER(ALL(Table),Table[Link ID] = __LinkID && Table[Order Date] = __LinkDate),[Link Status])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

You're a genius. Thank you for the quick response!!!

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors