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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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