Add a total's column to a stacked bar chart

Knowledge Drop

Last tested: Oct 14, 2020
 

Using Table Calculations, you can add a total column to a stacked bar chart. (Note: If your bar chart is not stacked, you can add a total column by simply checking the row totals box and pivoting on your dimension)

METHOD 1: TOTAL COLUMN WITH BREAKDOWN

  • Step 1: Configure your explore section so that it has one extra row than the number that you need to display. For example, in this graph we only want to display March - July, but we'll want to add 1 extra row so that we can display a total column at the end.

Screen Shot 2019-09-10 at 4.33.31 PM.png

  • Step 2: Create two table calculations. The first will create a column that displays the total of the series if it is the max row in the data set. The second will create a column that displays the word "Total" if it is the max row in the data set.

image.png

  • Step 3: Hide your original dimension and measure from the visualization so that only the table calculations and the pivoted columns remain in the visualization.

METHOD 2: TOTAL COLUMN WITHOUT BREAKDOWN (PRESERVES DRILLS)

image.png

The method used is very similar to Method 1. Step 1 is the same as we want to filter for 1 extra timeframe - above, weeks - to be able to display the total in a separate column. We should also enable totals on that Explore query.

The table calculations used are the following:

Created Week: if(row()=max(row()), "Total", to_string(${orders.created_week}))

Total: if(row()=max(row()),sum(pivot_row(${orders.count:total})), null)

Like in the previous method, hide the original timeframe dimension, and you're done! As we're still using the measure, users will still be able to drill into the chart if necessary.

This content is subject to limited support.                

Comments
keerthiks3107
New Member

Can you help me with the images? I cannot see the image. I have a similar requirement to show total of all the 3 stacked bars. 

vikram1
Bronze 3
Bronze 3

@keerthiks3107 - Have you got any solution of the problem?  I also have the same requirement.  

Version history
Last update:
‎04-05-2021 09:01 AM
Updated by: