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

calculating difference between current to previous most recent result per group

I have a table that looks similar to

 

controlresultdate
11220-9-2019
11522-9-2019
1923-9-2019
21020-9-2019
2522-9-2019
22323-9-2019
3820-9-2019
33422-9-2019
33023-9-2019

 

I want to create a calculated new column that shows the difference between the result on that row and the result on the closest previous date per control (results come in with irregular intervals)

 

I want it to end up looking like

 

controlresultdatedifference
11220-9-2019 
11522-9-20193
1923-9-2019-6
21020-9-2019 
2522-9-2019-5
22323-9-201918
3820-9-2019 
33422-9-201926
33023-9-2019-4

 

How do i do this?

 

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Refering to the post @amitchandak provide, I create these columns:

Index =
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        ALLEXCEPT ( 'Table', 'Table'[control] ),
        'Table'[date] < EARLIER ( 'Table'[date] )
    )
) + 1
Value Change =
'Table'[result]
    - CALCULATE (
        SUM ( 'Table'[result] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[control] ),
            'Table'[Index]
                = EARLIER ( 'Table'[Index] ) - 1
        )
    )

valuechange.PNG

 

Best Regards,

Icey

 

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
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Refering to the post @amitchandak provide, I create these columns:

Index =
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        ALLEXCEPT ( 'Table', 'Table'[control] ),
        'Table'[date] < EARLIER ( 'Table'[date] )
    )
) + 1
Value Change =
'Table'[result]
    - CALCULATE (
        SUM ( 'Table'[result] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[control] ),
            'Table'[Index]
                = EARLIER ( 'Table'[Index] ) - 1
        )
    )

valuechange.PNG

 

Best Regards,

Icey

 

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.