cancel
Showing results for
Did you mean:

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a \$100 discount. Register Now

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 Number Value Device 1 10 Device 2 20 Device 3 30 Device 4 40 Device 5 50 Device 6 60

Table 1

 Device Number Category Total Device 1 A Device 2 A Device 3 B Device 4 B 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?

 Category Value A 30 B 70 Uncategorised 10
2 REPLIES 2
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]) )

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]) )

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])
)

Announcements

#### Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

#### Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

#### Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

#### Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors