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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
martos360
Regular Visitor

Calculate total of uncategorised data for stacked column chart

Hi.

I am wanting to display data broken down by category on a stacked column chart. However the data is for the categories and the overall total, but the sum of all the categories is less than the total (meaning there is some uncategorised data). So I can only get the column chart to either show the overall total (with no breakdown per category), or the sum of the categories (but this is not the overall total).

 

This is different to typical examples I have seen where the total is simply aggregated from the relevant categories.

 

For example; Table 1 (which has the data from the devices) is linked to Table 2 which shows which devices are for which category and which are for the overall total.

 

Device NumberValue
Device 110
Device 220
Device 330
Device 440
Device 550
Device 660

Table 1

 

Device NumberCategoryTotal
Device 1A 
Device 2A 
Device 3B 
Device 4B 
Device 5 Yes
Device 6 Yes

Table 2

 

Category A total is 30 (Device 1 + Device 2), category B total is 70 (Device 3 + Device 4), and the overall total is 110 (Device 5 + Device 6). Is it possible for Power BI to calculate the value of the uncategorised data from the overall total minus the sum of all the categories [110 - (30 + 70)], so the stacked column chart shows the breakdown by category and the correct overall total? If so, what is the best way of doing this?

 

CategoryValue
A30
B70
Uncategorised10
2 REPLIES 2
martos360
Regular Visitor

@amitchandak Thank you so much for your help. With a few modifications I can now get the correct stacked column chart for the example data. The formula I used is:

Measure =

SWITCH(TRUE(),
MAX(Table2[Category]) = "Uncategorised", CALCULATE( SUM(Table1[Value]), Table2[Category] = BLANK() ) - CALCULATE( SUM(Table1[Value]), Table2[Category] <> BLANK() ),
SUM(Table1[Value]) )
Correct Output.PNG

However, for the real data there can be instances where a device is in a category and the overall total. So will need to refer to the Total column in table 2 rather than relying on the Category column being blank. However, when I update the measure to use the Total column, I get the wrong output. Do you know how to resolve this?

 

Measure =
SWITCH(TRUE(),
MAX(Table2[Category]) = "Uncategorised", CALCULATE( SUM(Table1[Value]), Table2[Total] = "Yes" ) - CALCULATE( SUM(Table1[Value]), Table2[Category] <> BLANK() ),
SUM(Table1[Value]) )

 Incorrect Output.PNG

 

 

 
amitchandak
Super User
Super User

@martos360 , In Power query replace null(all small) with Uncategorised or empty string with Uncategorised.

https://youtu.be/jAgz3HrT9sc

 

Join the two tables in Device number

 

Then you can have a one the following meausre

 

Measure =

Switch( True(),

max(Table[Category]) = "Uncategorised", calculate( sum(Table1[Sum]), Table2[Category] = "Uncategorised")- calculate( sum(Table1[Sum]), Table2[Category] <> "Uncategorised"),

sum(Table1[Sum]) )

 

Measure =
Switch( True(),
max(Table[Category]) = "Uncategorised",
calculate( sum(Table1[Sum]),filter(all(Table2), Table2[Category] = "Uncategorised"))- calculate( sum(Table1[Sum]),filter(all(Table2), Table2[Category] <> "Uncategorised")),
sum(Table1[Sum])
)

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.