Emman
Emman

Reputation: 4201

How to build a bar plot for funnel analysis when the raw data is boolean columns per person per month

I have data about people in different months. For each person, there's a row per month, for whether they were:

The data

# | person_id | month      | drank_below_2_cups_of_water | had_headache | died  |
# |-----------|------------|-----------------------------|--------------|-------|
# | 1         | 2024-02-01 | TRUE                        | TRUE         | FALSE |
# | 1         | 2024-03-01 | TRUE                        | FALSE        | TRUE  |
# | 2         | 2024-02-01 | FALSE                       | TRUE         | FALSE |
# | 2         | 2024-03-01 | TRUE                        | FALSE        | FALSE |
# | 3         | 2024-02-01 | FALSE                       | FALSE        | FALSE |
# | 3         | 2024-03-01 | TRUE                        | TRUE         | TRUE  |
# | 4         | 2024-02-01 | TRUE                        | FALSE        | FALSE |
# | 4         | 2024-03-01 | FALSE                       | TRUE         | TRUE  |
# | 5         | 2024-02-01 | FALSE                       | FALSE        | FALSE |
# | 5         | 2024-03-01 | TRUE                        | TRUE         | FALSE |
# | 6         | 2024-02-01 | FALSE                       | FALSE        | FALSE |
# | 6         | 2024-03-01 | TRUE                        | TRUE         | TRUE  |

What I'm trying to accomplish

Visualize a funnel analysis using a bar chart. Meaning:

enter image description here

Desired output

Two separate bar plots that visualize the counts above, yet in a different way of calculating the proportions between bars.

1 – Relative to first bar

relative_to_1st_bar

2 – Relative to previous bar

relative_to_prev_bar

It's critical that in either plot, I want to label both counts and proportions on bars top.

My current attempt to solve the problem

I tried creating separate calculated fields.

// A
sum(if [Drank Below 2 Cups Of Water] then 1 else 0 end)

// B
sum(if [Had Headache] AND [Drank Below 2 Cups Of Water] then 1 else 0 end)

// C
sum(if [Died] and [Had Headache] and [Drank Below 2 Cups Of Water] then 1 else 0 end)

// A (rel to A)
[A] / [A]

// B (rel to A)
[B] / [A]

// C (rel to A)
[C] / [A]

Then, bringing them over to the canvas as separate fields we get almost what I need. I just want to know how to add the counts too, not just the proportions (see below in red – that's what I'm still missing).

desired_output


Any idea how to achieve that? I'm open to any other suggestions, including structuring the data differently. I'm new to Tableau so looking for a best practice solution, as much as there is one.

Upvotes: 0

Views: 22

Answers (1)

MUFF.
MUFF.

Reputation: 791

Create a calculated field and call it [People Count]:

 COUNT([Person Id]) //or COUNTD if you want distinct counts, although odd if someone dies twice...

Drag [People Count] to the Label box in the Marks Pane

Format as needed.

Upvotes: 0

Related Questions