Calculating Customer Behavior Frequency in Tableau

By: Eric Parker

Pro Headshot.jpg

Eric Parker lives in Seattle and has been teaching Tableau and Alteryx since 2014. He's helped thousands of students solve their most pressing problems. If you have a question, feel free to reach out to him directly via email.

I’ve been working with a healthcare system that wants to do a better job of understanding patient behavior. Better understanding will drive decisions around staffing, purchasing, shift breaks, essentially the entire way the system is managed.

One of the questions they are looking to answer is, “How frequently do patients visit our system?” They’d like to know what portion of their population only visits once per year and how many visit 10+ times per year.

In this data set, each visit is listed as a single row of data.

130-1.png

To answer this question, I’m going to filter a worksheet down to the year in question and put a unique count (COUNTD) of patients that visited that year on Rows to create a vertical bar.

130-2.png

Now, I’d like to learn how many of those 366 patients visited just once, how many visited twice, etc. Unfortunately, there is no field called “Visits Per Patient”. In order to calculate visits per patient, I’m going to use a FIXED level of detail expressions which allows us to pre-calculate the number of visits at the patient level.

130-3.png

The [Visits Per Patient] calculation can now be converted into a Dimension in the data pane and then placed on the Columns shelf to generate the visit count labels.

130-4.png

This visual generally seems right, but if we look at it critically, we might have some concerns. For instance, were there really multiple people that visited the hospital 194 times in 2018?

130-5.png

The issue we are seeing is that the visit counts in the labels reflect the all-time number of visits per patient, not just the number of visits in 2018. That’s because FIXED level of detail expressions ensure that values are aggregated before standard dimension filters.

 
130-6.png
 

Source: Tableau.com

What we need to do is add the 2018 filter to context.

 
130-7.png
 

Once that’s done we have an accurate chart showing us how many times patients visited our system in 2018.

130-8.png

Want to learn more about Level of Detail Expressions in Tableau? Join us for our webinar next week, Unraveling the Mystery of Tableau Level of Detail Expressions!

Unraveling the Mystery of Tableau Level of Detail Expressions - Webinar Recording

Giving Your User Multiple Sorting Options with Tableau Parameters

0