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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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