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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
mcantos
Helper II
Helper II

Calculated Column Based on the max of a date in a different table

Hello, I hope this time you can also help me.

 

I have two related tables and I need to create a calculated column depending on one condition in the second table.

I need to add the new column in the Table1 Opportunities with the Stage name of the Table2 Stages with the Max  value on "Stage first starting date" 

 

Table 1. Opportunities

 

Opportunity IDOpportunity nameStatusStage name
1002ABCDActive 
1003EFGHDeclined 
1004IJKLOn Hold 

 

Table 2 Stages

Opportunity IDStage nameStart date
1002Initial1/2/2022
1002Triage1/7/2023
1002Discovery4/5/2023
1002Negotiation4/5/2022
1003Screening1/12/2020
1003Triage3/5/2022
1003Full Assessment3/5/2024

 

The result I'm expecting in Table 1 is :

Opportunity IDOpportunity nameStatusStage name
1002ABCDActive4/5/2023
1003EFGHDeclined3/5/2024
1003IJKLOn Hold 

 

Thank you so much in advance.

 

 

1 ACCEPTED SOLUTION

@mcantos ,Please find the updated measure

 

DAXMax Stage Name =
VAR MaxDate =
    CALCULATE(
        MAX(Stages[Start date]),
        FILTER(
            Stages,
            Stages[Opportunity ID] = Opportunities[Opportunity ID]
        )
    )
RETURN
    CALCULATE(
        MAX(Stages[Stage name]),
        FILTER(
            Stages,
            Stages[Opportunity ID] = Opportunities[Opportunity ID] &&
            Stages[Start date] = MaxDate
        )
    )



Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

6 REPLIES 6
bhanu_gautam
Super User
Super User

@mcantos , Use this measure and your output is incorrect as First Max date is 1/07/2023 for oppurtunity id 1002

 

Max Start Date =
VAR MaxDate =
    CALCULATE(
        MAX('Stages'[Start date]),
        FILTER(
            'Stages',
            'Stages'[Opportunity ID] = 'Opportunities'[Opportunity ID]
        )
    )
RETURN
    MaxDate



Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Thank you for your replay, 

 

Actually I made a mistake in the post. The result I'm expecting is th stage name instead of the date.

 

Sorry and thank you again. 

mcantos_0-1720698181736.png

 

@mcantos ,Please find the updated measure

 

DAXMax Stage Name =
VAR MaxDate =
    CALCULATE(
        MAX(Stages[Start date]),
        FILTER(
            Stages,
            Stages[Opportunity ID] = Opportunities[Opportunity ID]
        )
    )
RETURN
    CALCULATE(
        MAX(Stages[Stage name]),
        FILTER(
            Stages,
            Stages[Opportunity ID] = Opportunities[Opportunity ID] &&
            Stages[Start date] = MaxDate
        )
    )



Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Thanks a lot @bhanu_gautam , that was fast. 

 

It worked!! But now I have a situation where the max of the date does not work for some records and I have to select the second max date of the stage table.

 

Should I mark this as a solution and open a new ticket ?

Thank you again! 

Yes you should open new ticket with complete scenario , where you need to use second highest value 




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Arul
Super User
Super User

@mcantos ,

I assume Opportunity ID is the relationship column, Please refer the below,

Arul_0-1720694264421.png

Stage Name = CALCULATE( 
    MAX(Stages[Start date]))

 





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

Proud to be a Super User!


LinkedIn


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 Kudoed Authors