2 Replies Latest reply on Mar 24, 2016 6:20 PM by E Lin

Stacked bar chart for baby feeding data

I had a preemie baby and put together some data on how much (mL) she ate each day over two weeks. The types of nutrition were breastmilk (bottle), formula (bottle), and breastfeeding (estimated by multiplying the number of feeds by 7mL). I was able to create stacked area and bar charts for the absolute amounts per day using Measure Values:

but was not able to create a 100% stacked bar or area chart. I tried right-clicking and running Table Calculations for each individual pill under Measure Values, but that didn't work.

Any advice? Is my data structured badly? I'm very new to Tableau (today is my first time trying to use it) so appreciate any pointers. Thanks!

• 1. Re: Stacked bar chart for baby feeding data

You need to reshape your data.

In the attached I have a total by day.  (See [Total for day] calc).  But then to get the percentage of total for the day you would need to make 3 calcs, one for each measure.

Instead of having rows that have all three measures in each row, make three rows per day.  Have an extra dimension that has the type of feed (BF intake; ml Breastmilk; ml Formula), and have one measure that is simply [Amount].

for your stacked chart, you will have day on the columns, [Amount] on the rows, and put [feed type] on colors, and that will separate out the same three color chunks for you.

THEN your quick table calc for %of total will work, because it will be working on one measure that is separated by 3 dimension values.

As it stands now, the numbers you are getting are the %of total for each feed type over the span of dates on the sheet.

• 2. Re: Stacked bar chart for baby feeding data

Thank you! I will reshape the data. That seems to be the hardest part - getting the data in the right format!