Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Help getting table total to show total of individual rows

I am struggling with the common "total in table does not match the total of individual rows" issue. Have tried a number of the solutions on here but cant get any to work for my specific situation.

 

I need to calculate the total upsell on a customer by customer basis for one month compared to the previous month, but only include positive variances.

 

I have sales table (MRR) which has customerID, product type, date of sale, value of sale. I have separate measures for total sales in the current month (MRR end of period) and the previous month (MRR end of previous period) which seem to work fine

 

My DAX formula is as follows:

 

Upsell = SUMX (VALUES (MRR[CustomerID]), MAX([MRR End of period] - [MRR End of previous period],0))

 

I then put this in a table with a month column to show the total upsell in each month. It calculates correctly for each row in the table but the total is not the sum of the individual months. I know the reason for this (because the context has shifted from row context to the entire table) but I can't seem to derive an amended formula that gives the total I want. How do i fix it?

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

Its not enough to do a SUMX over the customers, you need to take the individual months into account as well so that for every month you are iterating over the customers for that month.

You can do that by creating a summary table which breaks your sales down by both month and customer, and then iterate over that.

Upsell =
VAR SummaryTable =
    SUMMARIZE ( MRR, MRR[CustomerID], 'Date'[Year month] )
VAR Result =
    SUMX (
        SummaryTable,
        MAX ( [MRR End of period] - [MRR End of previous period], 0 )
    )
RETURN
    Result

View solution in original post

3 REPLIES 3
Poojara_D12
Super User
Super User

Hi @Anonymous 

The issue you're facing with the total in your Power BI table not matching the sum of individual rows is a common DAX context problem. This occurs because, while your measure correctly calculates the upsell per customer at the row level, the total row evaluates the formula in a different context, applying the calculation to the entire dataset rather than summing up pre-calculated row values. Your current measure, SUMX(VALUES(MRR[CustomerID]), MAX([MRR End of period] - [MRR End of previous period],0)), attempts to compute the upsell by iterating over unique CustomerIDs. However, at the total level, VALUES(MRR[CustomerID]) returns all customers in the filter context, causing an incorrect evaluation. To fix this, you need to ensure that the total is a summation of individual positive upsell values, rather than a recalculated difference across all customers. A better approach is to use SUMX(VALUES(MRR[CustomerID]), IF([MRR End of period] - [MRR End of previous period] > 0, [MRR End of period] - [MRR End of previous period], 0)), which explicitly filters out negative values before summing them up. Alternatively, using SUMX(SUMMARIZE(MRR, MRR[CustomerID], "@Upsell", [MRR End of period] - [MRR End of previous period]), IF([@Upsell] > 0, [@Upsell], 0))  ensures that each customer’s upsell is first calculated individually before being aggregated. This method prevents the total row from recalculating based on a broader dataset context and instead sums the correct row-level values, resulting in an accurate total upsell figure for each month.

 

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos"

Kind Regards,
Poojara - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS
johnt75
Super User
Super User

Its not enough to do a SUMX over the customers, you need to take the individual months into account as well so that for every month you are iterating over the customers for that month.

You can do that by creating a summary table which breaks your sales down by both month and customer, and then iterate over that.

Upsell =
VAR SummaryTable =
    SUMMARIZE ( MRR, MRR[CustomerID], 'Date'[Year month] )
VAR Result =
    SUMX (
        SummaryTable,
        MAX ( [MRR End of period] - [MRR End of previous period], 0 )
    )
RETURN
    Result
Anonymous
Not applicable

Thanks, this work. I have a follow up question...

 

In the source data (which is just an excel spreadsheet) there may be blank cells for customers in certain months (i.e. there were no sales). Thus [MRR End of period] and [MRR End of previous period] may be blank

 

If I create a measure = MIN([MRR End of period] - [MRR End of previous period],0) then this will give an output of -100, say, if End of Period is blank and End of previous period is 100. Which is what I want

 

However, as soon as i put it in the SUMX function as per above, then it just returns blank, which is not the desired outcome.

 

Why is that and can i fix it. I have tried adding "+0" at various places in the measure to no avail

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.