I am trying to use the IF function to label Fitbit users according to their total average step count each day (across a period of 31 days). My goal is to create a nice simple pie chart with the percentage of users that fall into each category. However, for some reason when I used CountD for ID relative to the User Type - it doesn't give me all the options for user type. This is the correct calculation I need
IF AVG([Step Total]) <= 5000 THEN "Sedentary"
ELSEIF AVG([Step Total]) <= 7500 THEN "Lightly Active"
ELSEIF AVG([Step Total]) <= 9999 THEN "Fairly Active"
ELSEIF AVG([Step Total]) >= 10000 THEN "Very Active"
END
However, it doesn't work and leaves me with the image attached.
I then removed the "AVG" function. Leaving this:
IF ([Step Total]) <= 5000 THEN "Sedentary"
ELSEIF ([Step Total]) <= 7500 THEN "Lightly Active"
ELSEIF ([Step Total]) <= 9999 THEN "Fairly Active"
ELSEIF([Step Total]) >= 10000 THEN "Very Active"
END
This then gives me the correct summary table with each user however the numbers are not correct as now it is not the average Step Count but rather the ID count in the data (which consists of 31 days of step counts) that fall within the categories above.
Please see the picture below for more context.
The main thing I am trying to understand is the best method to categorize/group data in Tableau according to various fields. In R I would use the "group by" and "means" functions and so I am looking for a similar function in Tableau - would it be better to use the group or sets features?
Hello @Shann Thomson ,
I think you should give some aggregation for the if statement dimension and you usually don't get the percent of totals for the average aggregation. Just check with other aggregations if it is working or not in the calculated field.
Better post a extension file of the workbook that you are working on.
Thanks,
Hakitha.