March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe 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
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 |
@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 =
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]) )
@martos360 , In Power query replace null(all small) with Uncategorised or empty string with Uncategorised.
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])
)
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
124 | |
89 | |
84 | |
70 | |
51 |
User | Count |
---|---|
206 | |
143 | |
97 | |
79 | |
68 |