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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
QinisileD
Frequent Visitor

How to include the grand total in a stacked bar graph

Hello,

 

How can I ensure that the created stacked bar graph also displays the grand total?

I am using survey data, I did a crosstab (matrix) of 2 variables Province and Food adequancy and the measure is weighted food.

QinisileD_0-1619556854156.png

I want to populate the above results in a stacked bar graph, however, I am struggling to figure out how I can also display the Total "South Africa"

 

QinisileD_1-1619557082309.png

 

Kindly assist.

have 9 provinces and

1 ACCEPTED SOLUTION

Hi @QinisileD 

Sorry for late reply! You can create a Calculated column and create a Measure, then use them to create your visual.

 

The Calculated table:

Table =

UNION (

    SELECTCOLUMNS (

        Data,

        "province", Data[province],

        "food", Data[food],"weight",Data[benchwght]

    ),

    UNION (

        ROW (

            "province", " Total",

            "food", "No answer","weight",CALCULATE ( SUM (Data[benchwght]), FILTER ( Data, Data[food] = "No answer" ) )

        ),

        ROW (

            "province", " Total",

            "food", "Inadequate","weight",CALCULATE ( SUM (Data[benchwght]), FILTER ( Data, Data[food] = "Inadequate" ) )

        ),

        ROW (

            "province", " Total",

            "food", "Just adequate","weight",CALCULATE ( SUM (Data[benchwght]), FILTER ( Data, Data[food] = "Just adequate" ) )

        ),

        ROW (

            "province", " Total",

            "food", "More than adequate","weight",CALCULATE ( SUM (Data[benchwght]), FILTER ( Data, Data[food] = "More than adequate" ) )

        )

    )

)

 

The Measure:

Weighted =

VAR val1 =

    SUM ( 'Table'[weight] )

VAR val2 =

    CALCULATE ( SUM ( 'Table'[weight] ), ALLEXCEPT ( 'Table', 'Table'[province] ) )

RETURN

    val1 / val2

 

The result looks like this:

v-cazheng-msft_0-1620381968039.png

 

For more details, you can refer the attached pbix file.

 

Best Regards

Caiyun Zheng

 

 If this post helps, then please Accept it as the solution. Really appreciate!

View solution in original post

9 REPLIES 9
v-cazheng-msft
Community Support
Community Support

Hi @QinisileD 

I think you need create a new table in which contains a row with the values of total and then use it to create your visual. Here is a similar issue and there is a solution in it, you refer Grand Total to Stacked Column Graph.

If you still have questions, please don't hesitate to let me known and please provide a small part of sample data that does not involve sensitive information.

 

Best Regards

Caiyun Zheng

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

I am a beginner in using Power bi, not sure if this is the correct way to share the data. Kindly review the data on the attached link

 

https://app.powerbi.com/reportEmbed?reportId=42e89bd8-77db-4ad1-a62f-f876373a79ee&autoAuth=true&ctid...

 

https://app.powerbi.com/groups/me/reports/42e89bd8-77db-4ad1-a62f-f876373a79ee 

 

<iframe width="1140" height="541.25" src="https://app.powerbi.com/reportEmbed?reportId=42e89bd8-77db-4ad1-a62f-f876373a79ee&autoAuth=true&ctid..." frameborder="0" allowFullScreen="true"></iframe> 

 

@QinisileD 

Sorry, but I can't reach it. You can add tables in your reply and share some sample data in the form of table.

   

v-cazheng-msft_0-1620038230965.png

 

Best Regards

Caiyun Zheng

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution. Really appreciate!

 

 

Here is the table:

uniqueidyearprovince_nobenchwghtfood_adequencyprovincefoodlatitudelongitude
67132016114423,264673Western CapeMore than adequate22,07060-32,66060
6918201617415,9420942Western CapeJust adequate22,07060-32,66060
72016416616,752492Free StateJust adequate26,52710-28,70080
240201647508,741831Free StateInadequate26,52710-28,70080
60920162237,55024592Eastern CapeJust adequate26,57030-32,13230
127720162138,73128679Eastern CapeNo answer26,57030-32,13230
12792016283,121904391Eastern CapeInadequate26,57030-32,13230
1443201675055,7809921GautengInadequate28,01150-26,01940
1444201677583,6718312GautengJust adequate28,01150-26,01940
1445201675027,8155572GautengJust adequate28,01150-26,01940
1253201622057,6320243Eastern CapeMore than adequate26,57030-32,13230
158620167574,98231741GautengInadequate28,01150-26,01940
2647201657076,5842091KwaZulu-NatalInadequate30,44700-28,96510
2648201657493,6484722KwaZulu-NatalJust adequate30,44700-28,96510
2650201652175,3921861KwaZulu-NatalInadequate30,44700-28,96510
2665201654197,6476893KwaZulu-NatalMore than adequate30,44700-28,96510
421520169928,08828382LimpopoJust adequate29,34090-23,78450
421920169192,83191372LimpopoJust adequate29,34090-23,78450
4220201691346,3993053LimpopoMore than adequate29,34090-23,78450
4291201694493,3208781LimpopoInadequate29,34090-23,78450
461120168472,43405261MpumalangaInadequate30,13780-25,75690
5409201631927,7422773Northern CapeMore than adequate21,97490-28,93660
547720163521,50768943Northern CapeMore than adequate21,97490-28,93660
6023201662123,8516582North WestJust adequate25,23470-26,38560
6027201665665,7257273North WestMore than adequate25,23470-26,38560
60932016111974,790183Western CapeMore than adequate22,07060-32,66060
648320161375,73889543Western CapeMore than adequate22,07060-32,66060
225201646788,069393Free StateMore than adequate26,52710-28,70080
230201641323,7557951Free StateInadequate26,52710-28,70080
4581201683350,950212MpumalangaJust adequate30,13780-25,75690
4597201681269,4223362MpumalangaJust adequate30,13780-25,75690
460720168333,54496062MpumalangaJust adequate30,13780-25,75690
5143201637182,0432211Northern CapeInadequate21,97490-28,93660
5144201631141,1443071Northern CapeInadequate21,97490-28,93660
58552016622089,838311North WestInadequate25,23470-26,38560
5880201661586,6295139North WestNo answer25,23470-26,38560
5884201662171,5993862North WestJust adequate25,23470-26,38560
         

I am not sure why the Table is not in the correct Table format. Kindly note that the last digit/number of the benchwght relates to food_adequency (1-Inadequate, 2- Just adequate, 3- More than adequate, 8- do not know, 9- no answer).

Hi @QinisileD 

Sorry for late reply! You can create a Calculated column and create a Measure, then use them to create your visual.

 

The Calculated table:

Table =

UNION (

    SELECTCOLUMNS (

        Data,

        "province", Data[province],

        "food", Data[food],"weight",Data[benchwght]

    ),

    UNION (

        ROW (

            "province", " Total",

            "food", "No answer","weight",CALCULATE ( SUM (Data[benchwght]), FILTER ( Data, Data[food] = "No answer" ) )

        ),

        ROW (

            "province", " Total",

            "food", "Inadequate","weight",CALCULATE ( SUM (Data[benchwght]), FILTER ( Data, Data[food] = "Inadequate" ) )

        ),

        ROW (

            "province", " Total",

            "food", "Just adequate","weight",CALCULATE ( SUM (Data[benchwght]), FILTER ( Data, Data[food] = "Just adequate" ) )

        ),

        ROW (

            "province", " Total",

            "food", "More than adequate","weight",CALCULATE ( SUM (Data[benchwght]), FILTER ( Data, Data[food] = "More than adequate" ) )

        )

    )

)

 

The Measure:

Weighted =

VAR val1 =

    SUM ( 'Table'[weight] )

VAR val2 =

    CALCULATE ( SUM ( 'Table'[weight] ), ALLEXCEPT ( 'Table', 'Table'[province] ) )

RETURN

    val1 / val2

 

The result looks like this:

v-cazheng-msft_0-1620381968039.png

 

For more details, you can refer the attached pbix file.

 

Best Regards

Caiyun Zheng

 

 If this post helps, then please Accept it as the solution. Really appreciate!

Hi Caiyun,

 

Thanks a lot. What you recommended actually worked 👍

Is there a way in which I can use a slicer to filter with the created graph.

 

QinisileD_1-1620421503432.png

I would like the results to change as I select different years. 

 

Regards,

QinisileD

 

selimovd
Super User
Super User

Hey @QinisileD ,

 

can you show how the data looks like? What of those are columns, what measures, what hierarchies etc.?

Then it's easier get an idea. Usually the last row in a matrix should say "Total" and not "South Africa", so it's worth investigating the data.

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

 

Thank you for assisting, basically when power bi produced the matrix results I clicked the the Format icon and under subtotals (row subtotal labels) I changed "Total" to "South Africa" because South Africa has 9 provinces and the total should represent the country as a whole.

 

I am using survey data with 47752 cases and numerous variables, I do not know how to share it on this platform. I used

Column: Province - where people had to chose between 1-9 provinces to select their location;
Column: Food - people had to chose between 1-5 (1-inadequete, 2- just adequate, 3- more than adequete, 4 - do not know & 5- No answer); and 
A weight variable: benchwght
 
On the matrix table : Under rows I have (Province), columns (Food) and values (a measure which I calculated -
Weighted Food = DIVIDE(SUM('Data'[benchwght]), CALCULATE(SUM(Data[benchwght]),ALLSELECTED(Data[Food])))
 
My problem is that the stacked bar graph only shows the results from the 9 provinces and excludes the Total which in this case I named it South Africa.
 
I would like to produce a graph that is similar to the one below: 
QinisileD_0-1619585754832.png

I can change the names of the Provinces to abbreviations later. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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