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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Datediff with Multiple Possible End Dates

Hi, 

I'm trying to calculate the lead stage duration of Salesforce leads like this:

DATEDIFF('Lead'[Conversation_Date__c],'Lead'[Converted_Date_c],DAY)
 

Unfortunately there is no single way through the stages. 

So the end date would come from different stages depending on the next step, e.g. converted or closed. 

The stages can be: MQL, Open, Contact_Attempt, Conversation, Unqualified, Converted. They might appear more than once and can be in other order as well.

 

How can I use different stages, without them overwriting them?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

You can create a calculated column as below to get it, please find the details in the attachment.

Column = 
VAR _startdate =
    CALCULATE (
        MAX ( 'Table'[Conversation_Date__c] ),
        FILTER ( 'Table', 'Table'[Order] = EARLIER ( 'Table'[Order] ) )
    )
VAR _endate =
    SWITCH (
        [Stage],
        "Contact_Attempt", [Contact_Attempt_Date_c],
        "Converted", 'Table'[Converted_Date_c],
        "MQL", 'Table'[MQL_Date_c],
        "Open", 'Table'[Open_Date_c],
        "Unqualified", 'Table'[Unqualified_Date_c]
    )
RETURN
    DATEDIFF ( _startdate, _endate, DAY )

yingyinr_0-1678848188159.png

If the above one can't help you, please provide some raw data in your table (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @Anonymous ,

You can create a calculated column as below to get it, please find the details in the attachment.

Column = 
VAR _startdate =
    CALCULATE (
        MAX ( 'Table'[Conversation_Date__c] ),
        FILTER ( 'Table', 'Table'[Order] = EARLIER ( 'Table'[Order] ) )
    )
VAR _endate =
    SWITCH (
        [Stage],
        "Contact_Attempt", [Contact_Attempt_Date_c],
        "Converted", 'Table'[Converted_Date_c],
        "MQL", 'Table'[MQL_Date_c],
        "Open", 'Table'[Open_Date_c],
        "Unqualified", 'Table'[Unqualified_Date_c]
    )
RETURN
    DATEDIFF ( _startdate, _endate, DAY )

yingyinr_0-1678848188159.png

If the above one can't help you, please provide some raw data in your table (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

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.