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
Yggdrasill
Responsive Resident
Responsive Resident

De-cumulate values with dates and dimension

I have a table like so:

ID| Date| Value

1512321.7.2010121
1512328.7.2010211
151234.8.2010299
1512311.8.2010386
1512318.8.2010463
1512325.8.2010588
151231.9.2010645
151238.9.2010704
1512315.9.2010766
1599922.9.2010802
1599929.9.2010946
159996.10.2010991
1599913.10.20101006
1599920.10.20101021
1512313.7.20112
1512320.7.20118
1512327.7.201127
151233.8.201141
1512310.8.2011110
1512317.8.2011139
1512324.8.2011219
1512331.8.2011275
151237.9.2011312
1512314.9.2011373
1512321.9.2011404
1512328.9.2011428
159995.10.2011451
1599912.10.2011473
1599919.10.2011476


The values from the source are already cumulative. 

My desired output is this:
ID | Date| Value| Decumulative values

1512321.7.2010121121
1512328.7.201021190
151234.8.201029988
1512311.8.201038687
1512318.8.201046377
1512325.8.2010588125
151231.9.201064557
151238.9.201070459
1512315.9.201076662
1512322.9.201080236
1599929.9.2010946946
159996.10.201099145
1599913.10.2010100615
1599920.10.2010102115
1512313.7.201122
1512320.7.201186
1512327.7.20112719
151233.8.20114114
1512310.8.201111069
1512317.8.201113929
1512324.8.201121980
1512331.8.201127556
151237.9.201131237
1512314.9.201137361
1512321.9.201140431
1512328.9.201142824
159995.10.2011451451
1599912.10.201147322
1599919.10.20114763

 

So basically - De-cumulate the Cumulative values within each ID and YEAR


I'm trying to use EARLIER() but I'm kinda lost here

Appreciate your help 


2 ACCEPTED SOLUTIONS
Yggdrasill
Responsive Resident
Responsive Resident

Ok I just solved this one. Maybe there's a better way

De-cumulative value =
VAR _predate =
    CALCULATE (
        MAX ( 'Table'[Date] );
        FILTER ( 'Table'; 'Table'[Date] < EARLIER ( 'Table'[Date] ) );
        'Table'[ID] = EARLIER ( 'Table'[ID] );
        YEAR ( 'Table'[Date] ) = YEAR ( EARLIER ( 'Table'[Date] ) )
    )
VAR _prevalue =
    CALCULATE (
        SUM ( 'Table'[CumulativeValue] );
        FILTER ( 'Table'; 'Table'[Date] = _predate );
        'Table'[ID] = EARLIER ( 'Table'[ID] )
    )
RETURN
    'Table'[CumulativeValue] - _prevalue

View solution in original post

Hi @Yggdrasill ,

 

I have another solution that needs an index column. Then use EARLIER() function to get previous row value. 

ValueDiff =
Table1[Value]
    - CALCULATE (
        FIRSTNONBLANK ( Table1[Value], 1 ),
        FILTER (
            Table1,
            Table1[Index]
                = EARLIER ( Table1[Index] ) - 1
                && Table1[ID] = EARLIER ( Table1[ID] )
        )
    )

3-1.PNG

You can try my method and consider which one is more acceptable.

 

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

View solution in original post

2 REPLIES 2
Yggdrasill
Responsive Resident
Responsive Resident

Ok I just solved this one. Maybe there's a better way

De-cumulative value =
VAR _predate =
    CALCULATE (
        MAX ( 'Table'[Date] );
        FILTER ( 'Table'; 'Table'[Date] < EARLIER ( 'Table'[Date] ) );
        'Table'[ID] = EARLIER ( 'Table'[ID] );
        YEAR ( 'Table'[Date] ) = YEAR ( EARLIER ( 'Table'[Date] ) )
    )
VAR _prevalue =
    CALCULATE (
        SUM ( 'Table'[CumulativeValue] );
        FILTER ( 'Table'; 'Table'[Date] = _predate );
        'Table'[ID] = EARLIER ( 'Table'[ID] )
    )
RETURN
    'Table'[CumulativeValue] - _prevalue

Hi @Yggdrasill ,

 

I have another solution that needs an index column. Then use EARLIER() function to get previous row value. 

ValueDiff =
Table1[Value]
    - CALCULATE (
        FIRSTNONBLANK ( Table1[Value], 1 ),
        FILTER (
            Table1,
            Table1[Index]
                = EARLIER ( Table1[Index] ) - 1
                && Table1[ID] = EARLIER ( Table1[ID] )
        )
    )

3-1.PNG

You can try my method and consider which one is more acceptable.

 

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

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.