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
Anonymous
Not applicable

Totals in matrix not correct

Hi all,

I'm currently working with the following dataset:

 

DateEnd CustomerChannelDistributorRegionProductUnitsPriceRevenue
01/03/2020AWholesalerA LtdUKP001102.525
01/03/2020BTradeA LtdUKP001203.162
01/03/2020CDomesticA LtdUKP002000
01/03/2020DWholesalerB LtdROIP002401.872
01/03/2020ETradeB LtdROIP002000
01/03/2020FDomesticB LtdROIP002601.696
01/03/2020GCommercialB LtdROIP003502.7135
01/03/2020HTradeC LtdFranceP00341.546.16
01/02/2020AWholesalerA LtdUKP00182.4519.6
01/02/2020BTradeA LtdUKP001000
01/02/2020CDomesticA LtdUKP002153.146.5
01/02/2020DWholesalerB LtdROIP002101.9519.5
01/02/2020ETradeB LtdROIP0025210
01/02/2020FDomesticB LtdROIP002000
01/02/2020GCommercialB LtdROIP003122.9535.4
01/02/2020HTradeC LtdFranceP003101.5415.4
01/01/2020AWholesalerA LtdUKP001202.652
01/01/2020BTradeA LtdUKP00130390
01/01/2020CDomesticA LtdUKP00223.46.8
01/01/2020DWholesalerB LtdROIP00225250
01/01/2020ETradeB LtdROIP002161.524
01/01/2020FDomesticB LtdROIP00251.829.1
01/01/2020GCommercialB LtdROIP003000
01/01/2020HTradeC LtdFranceP003221.124.2

I'm trying to calculate the price variance by "Channel" from one month to the next (01/03/2020 vs 01/02/2020). In the table below, you can see the result I'm getting for [Price Var]:

price variance.png

The dax measure is as follows:

 

 

Price Var = 
VAR Intervals = MonthsPrior[MonthsPrior Value]
VAR PricePriorPeriod =
CALCULATE(
    [Average Price],
    DATEADD( Data[Date], (Intervals *-1), MONTH)
)
RETURN
IF(
    ISFILTERED( Data[Channel] ),
    ( [Average Price] - [Price Prior Period] ) * SUM( Data[Units] ),
    SUMX(
        Data,
        (Data[Price] - PricePriorPeriod) * Data[Units]
    )
)

 

 

The totals for each individual channel (line totals) are correct... however the grand total at the bottom is incorrect. The grand total should be a sum of each Channel's total. i.e:
-12.5 + -90 + 27.52 + -11.61 = -86.59

The total I'm looking for in the grand total line is -86.59

Additional measures for reference:

Average Price

 

 

Average Price = 
DIVIDE( 
    SUM(Data[Revenue]), 
    SUM(Data[Units] )
)

 

 

Price Prior Period

 

 

Price Prior Period = 
VAR Intervals = MonthsPrior[MonthsPrior Value]
RETURN
CALCULATE(
    [Average Price],
    DATEADD( Data[Date], (Intervals *-1), MONTH)
)

 

 

Any help would be very much appreciated!
Thanks,
Aaron

10 REPLIES 10
Greg_Deckler
Community Champion
Community Champion

@Anonymous This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi @Greg_Deckler ,


Thanks for responding so quickly!

I updated my measure to this:

Price Var = 
IF(
    HASONEFILTER( Data[Channel] ),
    ( [Average Price] - [Price Prior Period] ) * SUM( Data[Units] ),
    SUMX(
        Data,
        (Data[Price] - [Price Prior Period]) * Data[Units]
    )
)

 

However, I'm still not getting the expected result. My result becomes 396.16 instead of -86.59.

 

I think this probably has something to do with the fact that I am trying to subtract the current period price (this is defined by the user in a date filter on the page) by the price in the period prior to the selected period.

 

If you take a look at the screenshot below, I have defined the period as 01/03/2020 and the "MonthsPrior" parameter is set to 1, therefore the (Prior Month) measures are displaying the figures for 01/02/2020. The actual line by line results for Price Var are correct, just not the total! 😞

 

Any thoughts?

 

price var.png

Aaron

@Anonymous 

You need to use SUMMARIZE or GROUPBY based upon how you are grouping things in the visual:

Price Var = 
IF(
    HASONEFILTER( Data[Channel] ),
    ( [Average Price] - [Price Prior Period] ) * SUM( Data[Units] ),
    SUMX(
        Data, //this generally needs to be a SUMMARIZE or GROUPBY of the table based upon how data is grouped/summarized in the table/matrix
        (Data[Price] - [Price Prior Period]) * Data[Units]
    )
)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi @Greg_Deckler 

I tried the following but I'm getting an error:


"The CALCULATE function cannot be used in an expression argument for the GROUPBY() function."

 

Price Var = 
IF(
    HASONEFILTER( Data[Channel] ),
    ( [Average Price] - [Price Prior Period] ) * SUM( Data[Units] ),
    GROUPBY(
        Data,
        Data[Channel],
        "Price Variance", 
        SUMX(
            CURRENTGROUP(),
            ( Data[Price] - [Price Prior Period] ) * Data[Units]
        )
    )
)

 

Is this because I'm trying to use the [Price Prior Period] measure which uses CALCULATE?

 

Price Prior Period = 
VAR Intervals = MonthsPrior[MonthsPrior Value]
RETURN
CALCULATE(
    [Average Price],
    DATEADD( Data[Date], (Intervals *-1), MONTH)
)

 

@Anonymous Yet another reason I do not like CALCULATE, or T"I" functions. 

https://community.powerbi.com/t5/Community-Blog/CALCUHATE-Why-I-Don-t-Use-DAX-s-CALCULATE-Function/ba-p/1248635

https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler 

Any advice how I would therefore update my measure to make it work? Given the dataset above etc?

@Anonymous Well, maybe try SUMMARIZE instead of GROUPBY but otherwise would need to mock it up and get rid of T"I" and CALCULATE functions using something like AVERAGEX and whatever FILTER is necessary to get rid of DATEADD (like EOMONTH, etc.) Would take some time to unwind. Would need all of your formulas. Any chance you can share PBIX to speed things up?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Anonymous OK, I've got it downloaded, I'll try to review today and see if I can get it unwound.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

You are a hero! Thank you! 😊

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.

Top Solution Authors