Skip to main content
Agustín Suárez a posé une question dans #Tableau Cloud

Hi! A superb newbie here!

I am trying to recreate a stacked horizontal bar chart as in the image below:

100% Stacked Bar Chart - Dimension values from aggregation (average)I have the following dummy data schema:

User (str) | question (str) | category (str) | persona (str) | score (int)

1 | 1 | a | x | 3

1 | 2 | a | x | 4

...

9 |2 | a | z | 2

 

Using averages from score, I need to calculate if the User is favorable (avg > 3), unfavorable (avg < 3) or neutral (avg = 3).

 

My calculated formula to create the favorable score is:

IF AVG([Score]) > 3 THEN "Favorable"

ELSEIF AVG([Score]) < 3 THEN "Unfavorable"

ELSE "Neutral" END

It seems to work properly, and I can even add filters that change the result correctly for other dimensions like persona (what I also intend to do). However, I am not near to displaying the results as shown in the chart above. This is the closest I have achieved:

imageIf I were to do it on SQL, I would use this:

WITH averages AS (

SELECT

USER

, CASE

WHEN avg(SCORE) > 3 THEN 'favorable'

WHEN avg(SCORE) < 3 THEN 'unfavorable'

ELSE 'Neutral'

END AS score_factor

FROM

tbl

-- use WHERE Clausel for filter

GROUP BY

1

)

SELECT

score_factor

, count(USER) n_users

, ratio_to_report(n_users) OVER () AS percent_users

FROM

averages

GROUP BY

1

and then plot percent_users as values and score_factor as dimension.

 

I am attaching the Tableau Workbook with some dummy data and my calculated field.

 

Any support will be very welcomed!!

 

Best Regards,

Agustin

2 réponses
0/9000