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
RogerSteinberg
Post Patron
Post Patron

Column subtotal of my matrix not being summed properly

Hi,

 

I have this measure which gives me the ratio of revenue to cost. My table has several dimensions such as date, country, product and so on.

My matrix has the following fields:

Rows:

Start Date, Total Cost

Columns:

Revenue Month

Values:

Formula

 

Formula = 
var num = 
SUMX(
    'Fact',
    'Fact'[Revenue]
)
VAR den = 
SUMX(
    'Fact',
    'Fact'[Actual Cost]
)
RETURN
DIVIDE(
    num,
    den
)

 

 My values are good. My issue lies in the Column subtotal of my matrix. I would like that column to sum the entire row values. Instead, it seems to be aggregating the revenue column and dividing it by the cost column for the entire grouping which is not what I want.

 

My intended result should look like this

Start DateCost1-Jan1-Feb1-Mar1-Apr1-MayTotal
1-Jan $   10.0020%30%40%50%60%200%
1-Feb $   20.00 20%30%45%60%155%
1-Mar $   25.00  32%45%60%137%

As you can see it is summing all the % for its respective row to give the column subtotal

Instead it is doing something like this:

Start DateCost1-Jan1-Feb1-Mar1-Apr1-MayTotal
1-Jan $   10.0020%30%40%50%60%45%
1-Feb $   20.00 20%30%45%60%40%
1-Mar $   25.00  32%45%60%35%
1 ACCEPTED SOLUTION

Hi @RogerSteinberg

 

I just wanna show you a method about calculating the total value in row,not meant to modify your expression.

You can create 2 measures as below:

_Formula = 
var num = 
SUMX(
    FILTER('Fact','Fact'[Revenue Month]=MAX('Fact'[Revenue Month])),
    'Fact'[Revenue]
)
VAR den = 
MAX('Fact'[TotalCost by YearMonth])
RETURN
DIVIDE(
    num,
    den
)
_Total = SUMX(VALUES('Fact'[Revenue Month]),'Fact'[_Formula])

And you will see:

Annotation 2020-08-19 163316.png

For the related .pbix file,pls click here.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

View solution in original post

7 REPLIES 7
pranit828
Community Champion
Community Champion

HI @RogerSteinberg 

 

On the values section

pranit828_1-1597705323607.png

Is Sum selected for the column'Total'

pranit828_2-1597705407308.png

If the above approach doesn't work then I would create a measure as below.

 

_Total = 
     CALCULATE(SUMX('Fact','Fact'[Formula]), ALLEXCEPT('Fact','Fact'[Start Date],'Fact'[Cost]))




PBI_SuperUser_Rank@1x.png


Hope it resolves your issue? 
Did I answer your question? Mark my post as a solution!

Appreciate your Kudos, Press the thumbs up button!!
Linkedin Profile

It can only be a measure.

 

Unfortunately the allexcept suggestion doesn't work. It does the opposite. The values are not matching but the subtotal works.

Hi  @RogerSteinberg ,

 

Can you upload your .pbix file to onedrive business and share the link with us?

 

Remember to remove the confidential information.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

Here's raw data:

StartProductCostRevenueRevenue Month
1-JanA10201-Jan
1-JanA10301-Feb
1-JanA10401-Mar
1-FebA20251-Feb
1-FebA20301-Mar
1-FebA20351-Apr
1-JanB25251-Jan
1-JanB25401-Feb
1-JanB25701-Mar
1-FebB50601-Feb
1-FebB50701-Mar
1-FebB50901-Apr

And the Calculated column for the cost by Month :

TotalCost by YearMonth = 
CALCULATE(
    SUMX( 
        VALUES('Fact'[Product] ), 
        CALCULATE(AVERAGE('Fact'[Cost])) 
        ),
    ALLEXCEPT(
        'Fact',
        'Fact'[Start]
        )
)

Hi  @RogerSteinberg ,

 

Create 2 measures as below:

 

_Average  = CALCULATE(AVERAGE('Fact'[Cost]),FILTER(ALL('Fact'),'Fact'[Product]=MAX('Fact'[Product])&&'Fact'[Start]=MAX('Fact'[Start])))

 

 

_Total = SUMX(VALUES('Fact'[Revenue Month]),'Fact'[_Average])&"%"

 

And you will see:

Annotation 2020-08-18 164504.png

For the related .pbix file,pls click here.

 

I think your formular should be modified as below:

 

 

TotalCost by YearMonth = 
CALCULATE(
    SUMX( 
        VALUES('Fact'[Revenue Month] ), 
        CALCULATE(AVERAGE('Fact'[Cost])) 
        ),
    ALLEXCEPT(
        'Fact',
        'Fact'[Start]
        )
)

 

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

Two things.

 

For the first measure im not sure why you use cost. Please see my initial question which explains how the values are to be aggregated. I've also included the intended result below.

 

The formula for the values should be the ratio of Revenue to Cost. In other words, sum the revenue for the revenue month associated to the start month divided by the cost for that cohort.

This gives me the right values, but the aggregation doesn't work for my Column Subtotals

DIVIDE(
    SUMX(
        'Fact',
        'Fact'[Revenue]
    )
    ,
    SUMX(
        'Fact',
        'Fact'[Cost]
    ))

Second, my formula for TotalCost by Month is correct. No need to change it. This formula is the aggregation of cost grouped by start month and revenue month. It removes duplicates

 

Here is the intended result

StartCost1-Jan1-Feb1-Mar1-AprTotals
1-Jan35129%200%314% 643%
1-Feb70 121%157%179%457%

 

For the value 1-Jan for row Jan 1 which is 129 % it is calculated as such:

(20+25)/35 = 1.29 = 129%

For the value 1-Feb for row Jan1 which is 200% it is calculated as such:

(30+40)/35 =2 = 200%

2020-08-18 10_05_36-PBITest - Power BI Desktop.png

result.png

Hi @RogerSteinberg

 

I just wanna show you a method about calculating the total value in row,not meant to modify your expression.

You can create 2 measures as below:

_Formula = 
var num = 
SUMX(
    FILTER('Fact','Fact'[Revenue Month]=MAX('Fact'[Revenue Month])),
    'Fact'[Revenue]
)
VAR den = 
MAX('Fact'[TotalCost by YearMonth])
RETURN
DIVIDE(
    num,
    den
)
_Total = SUMX(VALUES('Fact'[Revenue Month]),'Fact'[_Formula])

And you will see:

Annotation 2020-08-19 163316.png

For the related .pbix file,pls click here.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

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.