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
shishir999
Helper II
Helper II

Calculate Difference between change in value

Hi,

 

In general, we calculate the Cummulative Total of the values, but my requirement is to get the each day change in value based on Cummulative values. See the attachement. 

 

Ctg_Sample.JPG

 

Left side table is my Main dataset and right side one are the expected result.

How to calculate the change in values based on Running Total, as see the GREEN Color field.

Also, this could be a running total for all Category as well.

 

Thanks

Shishir

 

 

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@shishir999

 

Try this pattern

 

Calc col =
[Value]
    - MINX (
        TOPN (
            1,
            FILTER ( Table1, [Ctg] = EARLIER ( [Ctg] ) && [Date] < EARLIER ( [Date] ) ),
            [Date], DESC
        ),
        [Value]
    )

Regards
Zubair

Please try my custom visuals

View solution in original post

5 REPLIES 5
Zubair_Muhammad
Community Champion
Community Champion

@shishir999

 

Try this pattern

 

Calc col =
[Value]
    - MINX (
        TOPN (
            1,
            FILTER ( Table1, [Ctg] = EARLIER ( [Ctg] ) && [Date] < EARLIER ( [Date] ) ),
            [Date], DESC
        ),
        [Value]
    )

Regards
Zubair

Please try my custom visuals

Thanks Zubair for the solution. 

 

I was trying this earlier: 

*********************** 

Var Mx = CALCULATE(MAXX(table, [Value]),
FILTER(table,
[Date] <= EARLIER([Date])
))
Var Mi = CALCULATE(MAXX(Table,[value]),
FILTER(table,
[Date] = MIN([Date])
))
Var diff = Mx- Mi
Return
diff

***************************  

 

Could you please help me to understand the Top 1 use..

 

Thanks

Shishir

@shishir999

 

This is how it works for each row to get the previous Cumulative Value

 

1) First Filter gets a filtered table with all dates less than current row date

2) TOPN on this Filtered Table gets the lastrow from the Filtered Table

3) MINX is used to get the Value on this Date

 

so basically the flow is MINX<<<TOPN<<<<Filter


Regards
Zubair

Please try my custom visuals

Hi Zubair,

 

I need one more help here.

 

Scenario_Prune_Incr.JPG

 

In the same query, how can I restrict that my 1st min. value must remain ZERO and after that, if any changes in the value, it will calculate it, as the exisiting query working.

 

 

 

Thanks

Shishir G.

Thanks alot for explaination.

 

Regards

Shishir Goel

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.