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
NPC
Helper I
Helper I

Subtract Same Row Dates

Hello,

 

I need to be able to subtract dates from the same row.

- Specifically, I care only about the date differnce btween the Statuses "SFT" and "REA" and only if they follow each other.

- If "SFT" is nt follwed by "REA", then I don't need the calculation. I deally, I would like for those to be left blank. 

- For example, for Equip_Num 367584264, I would like to calculate the Date_Difference between 5/17/2022 and 5/24/2022.

 

Here is what the table looks like:

Equip_NumStatusCompleted OnDate_Difference
367584264SFT5/1/2022 
367584264RVW5/13/2022 
367584264SFT5/17/2022 
367584264REA5/24/2022 
367584265RVW5/11/2022 
367584265SFT5/15/2022 
367584265REA5/20/2022 
367584266RVW5/2/2022 
367584266SFT5/3/2022 

 

Thank you!

 

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @NPC 

 

You can try the following methods.

Column:

Previous Date =
MAXX (
    FILTER (
        'Table',
        [Completed On] < EARLIER ( 'Table'[Completed On] )
            && [Equip_Num] = EARLIER ( 'Table'[Equip_Num] )
    ),
    [Completed On]
)
Previous Status =
CALCULATE (
    MAX ( 'Table'[Status] ),
    FILTER (
        'Table',
        [Equip_Num] = EARLIER ( 'Table'[Equip_Num] )
            && [Completed On] = EARLIER ( 'Table'[Previous Date] )
    )
)
Follow = IF([Status]="REA"&&[Previous Status]="SFT",1,BLANK())
Date_Difference = IF([Follow]=1,[Completed On]-[Previous Date],BLANK())

vzhangti_0-1654502616260.png

Is this the output you expect?

 

Best Regards,

Community Support Team _Charlotte

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

2 REPLIES 2
NPC
Helper I
Helper I

Thank you, this works!

v-zhangti
Community Support
Community Support

Hi, @NPC 

 

You can try the following methods.

Column:

Previous Date =
MAXX (
    FILTER (
        'Table',
        [Completed On] < EARLIER ( 'Table'[Completed On] )
            && [Equip_Num] = EARLIER ( 'Table'[Equip_Num] )
    ),
    [Completed On]
)
Previous Status =
CALCULATE (
    MAX ( 'Table'[Status] ),
    FILTER (
        'Table',
        [Equip_Num] = EARLIER ( 'Table'[Equip_Num] )
            && [Completed On] = EARLIER ( 'Table'[Previous Date] )
    )
)
Follow = IF([Status]="REA"&&[Previous Status]="SFT",1,BLANK())
Date_Difference = IF([Follow]=1,[Completed On]-[Previous Date],BLANK())

vzhangti_0-1654502616260.png

Is this the output you expect?

 

Best Regards,

Community Support Team _Charlotte

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.