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
hyby_tt
Frequent Visitor

Cumulative sum of absolute differences

Hello,


The issue :

We try to measure the precision of our teams between the budget they target and what they actually spend.
So it's important that we use the cumulative of absolute differences (however the delta is negative or positive)
I have many line in my dataset because users can filter on many things

To simplify what I try to achieve I made this table :

MonthBudgetActualRelative differenceAbsolute differenceWhat I try to calculate
January1000900100100100
February8001000-200200300
March12001300-100100400


The table looks like something like (2 last columns make the link with the previous table) :

MonthTeamtypeBudgetActualtot budgettot Actual
JanuaryA12503001000900
JanuaryA2250200
JanuaryB1250150
JanuaryB2250300
FebruaryA12001008001000
FebruaryA2200300
FebruaryB1200200
FebruaryB2200200
MarchA130040012001300
MarchA2300200
MarchB1300300
MarchB2300400


What I tried :

var f = CALCULATE(SUM(Actuals_Profiling[Cost]),Actuals_Profiling[cost_type]="Actual")
var g = CALCULATE(SUM(Actuals_Profiling[Cost]),Actuals_Profiling[cost_type]="Profiling")

var h = ABS(g-f)

var i =
sumx(SUMMARIZE('Working days',
'Working days'[fmonth],
"absolute",
h),[absolute])

return
i

It doesnt work
any idea ?
1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @hyby_tt ,

According to your description, Actual and Budget are two columns in the table, but in your formula, it seems not the same structure. Based on your formula, I create a sample.

vkalyjmsft_0-1656070657694.png

You have two tables: Actuals_Profiling and Working days. I'm not clear about the relationship, so there's only one table in my sample. Here's my solution.

Create two measures.

Absolute difference = 
VAR f =
    CALCULATE (
        SUM ( Actuals_Profiling[Cost] ),
        FILTER(ALL('Actuals_Profiling'),Actuals_Profiling[cost_type] = "Actual"&&'Actuals_Profiling'[Month]=MAX('Actuals_Profiling'[Month])
    ))
VAR g =
    CALCULATE (
        SUM ( Actuals_Profiling[Cost] ),
        FILTER(ALL('Actuals_Profiling'),Actuals_Profiling[cost_type] = "Profiling"&&'Actuals_Profiling'[Month]=MAX('Actuals_Profiling'[Month])
    ))
VAR h =
    ABS (g-f)

RETURN
    h
Accumulate difference =
SUMX (
    FILTER (
        ALL ( 'Actuals_Profiling' ),
        'Actuals_Profiling'[Month] <= MAX ( 'Actuals_Profiling'[Month] )
    ),
    'Actuals_Profiling'[Absolute difference]
)
    / COUNTROWS (
        FILTER (
            ALL ( 'Actuals_Profiling' ),
            'Actuals_Profiling'[Month] = MAX ( 'Actuals_Profiling'[Month] )
        )
    )

Get the result.

vkalyjmsft_1-1656070987981.png

I attach my sample for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

4 REPLIES 4
v-yanjiang-msft
Community Support
Community Support

Hi @hyby_tt ,

According to your description, Actual and Budget are two columns in the table, but in your formula, it seems not the same structure. Based on your formula, I create a sample.

vkalyjmsft_0-1656070657694.png

You have two tables: Actuals_Profiling and Working days. I'm not clear about the relationship, so there's only one table in my sample. Here's my solution.

Create two measures.

Absolute difference = 
VAR f =
    CALCULATE (
        SUM ( Actuals_Profiling[Cost] ),
        FILTER(ALL('Actuals_Profiling'),Actuals_Profiling[cost_type] = "Actual"&&'Actuals_Profiling'[Month]=MAX('Actuals_Profiling'[Month])
    ))
VAR g =
    CALCULATE (
        SUM ( Actuals_Profiling[Cost] ),
        FILTER(ALL('Actuals_Profiling'),Actuals_Profiling[cost_type] = "Profiling"&&'Actuals_Profiling'[Month]=MAX('Actuals_Profiling'[Month])
    ))
VAR h =
    ABS (g-f)

RETURN
    h
Accumulate difference =
SUMX (
    FILTER (
        ALL ( 'Actuals_Profiling' ),
        'Actuals_Profiling'[Month] <= MAX ( 'Actuals_Profiling'[Month] )
    ),
    'Actuals_Profiling'[Absolute difference]
)
    / COUNTROWS (
        FILTER (
            ALL ( 'Actuals_Profiling' ),
            'Actuals_Profiling'[Month] = MAX ( 'Actuals_Profiling'[Month] )
        )
    )

Get the result.

vkalyjmsft_1-1656070987981.png

I attach my sample for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

vapid128
Solution Specialist
Solution Specialist

That is my table, just copy the table and copy the Measure and Measure 2

Month Team type Budget Actual Month_Number
January A 1 250 300 1
January A 2 250 200 1
January B 1 250 150 1
January B 2 250 300 1
February A 1 200 100 2
February A 2 200 300 2
February B 1 200 200 2
February B 2 200 200 2
March A 1 300 400 3
March A 2 300 200 3
March B 1 300 300 3
March B 2 300 400 3

 

vapid128
Solution Specialist
Solution Specialist

I am confused where are the total Actual come from.

Jan 300+200+150+300 = 950

Feb 100+300+200+200 =800

 

If it is only calculation mistake:

 

Measure = SUMX(VALUES('Table'[Month]),CALCULATE(ABS(SUM('Table'[Actual])-SUM('Table'[Budget]))))

 

vapid128_0-1655428124403.png

Measure 2 = 
var monthindex = MAX('Table'[Month_Number])
return
CALCULATE([Measure],FILTER(ALLSELECTED('Table'),[Month_Number]<=monthindex))

vapid128_1-1655428605093.png

 

Hello,

Thank you for your help,

You assumed correctly, I made a mistake and the the total by month should match between first and seconde table.
However I tried your solution and it doesn't work for me

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.