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

Substract 2 date from differente row relate by a key

Hi i want to substract 2 date relate by a opportunity number(key) but that are in differente row but i dont know if it possible to it and how. For example

account numberdatesale stage
14/5/2019identified
14/1/2020qualified
14/7/2020proposal

I wonder is there a way to get the time difference between when the sale stage = identified and when the sale stage = qualified for account number 1.

 

Thank you

1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

HI, @Anonymous 

Just use EARLIER in this formula to create a new column

time difference = 
VAR _identified =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER (
            'Table',
            [account number] = EARLIER ( [account number] )
                && [sale stage] = "identified"
        )
    )
VAR _qualified =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER (
            'Table',
            [account number] = EARLIER ( [account number] )
                && [sale stage] = "qualified"
        )
    )
RETURN
    DATEDIFF ( _identified, _qualified, DAY )

or

time difference 2 = 
VAR _identified =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER (
            'Table',
            [account number] = EARLIER ( [account number] )
                && [sale stage] = "identified"
        )
    )
VAR _qualified =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER (
            'Table',
            [account number] = EARLIER ( [account number] )
                && [sale stage] = "qualified"
        )
    )
RETURN
   IF( [sale stage] = "qualified"||[sale stage] = "identified", DATEDIFF ( _identified, _qualified, DAY ))

 

Result:

4.JPG

 

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-lili6-msft
Community Support
Community Support

HI, @Anonymous 

Just use EARLIER in this formula to create a new column

time difference = 
VAR _identified =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER (
            'Table',
            [account number] = EARLIER ( [account number] )
                && [sale stage] = "identified"
        )
    )
VAR _qualified =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER (
            'Table',
            [account number] = EARLIER ( [account number] )
                && [sale stage] = "qualified"
        )
    )
RETURN
    DATEDIFF ( _identified, _qualified, DAY )

or

time difference 2 = 
VAR _identified =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER (
            'Table',
            [account number] = EARLIER ( [account number] )
                && [sale stage] = "identified"
        )
    )
VAR _qualified =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER (
            'Table',
            [account number] = EARLIER ( [account number] )
                && [sale stage] = "qualified"
        )
    )
RETURN
   IF( [sale stage] = "qualified"||[sale stage] = "identified", DATEDIFF ( _identified, _qualified, DAY ))

 

Result:

4.JPG

 

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thank you !!! it works perfectly

hi, @Anonymous 

It's pleasant that your problem has been solved, could you please mark the reply as Answered?

 

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.