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

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