Get startedGet started for free

Start to calculate in Tableau

1. Start to calculate in Tableau

In this first demo, we will be focusing on Fitbit users' sleep statistics. Let’s see how we can create our calculations. We would like to study sleep efficiency, so ultimately the ratio of Minutes Asleep in Total time in Bed, so let’s do it step by step. We will first add the User IDs to the canvas, and we’ll add the summed Time in Bed as a measure. Suppose we want to calculate an overall average time in bed per user per day. The underlying data contains multiple sleep records per user per day, so we cannot just change the aggregation to the average and remove the user ID from the canvas. We need to calculate it. Let’s clear the canvas and prepare the calculation. In Tableau, there are multiple ways to build a calculation: We can either click on Analysis > Create a calculated field: Or on a small arrow here: Or right-click on any empty space in the Data Pane. Let’s choose this option. A calculation editor will pop up! Let’s start by giving our calculation a meaningful name: Time in bed per user per day. We can now start typing the functions and data fields in the editor. Tableau will prompt us with existing data fields. We’ll go ahead and finish typing the calculation, dividing summed Time in Bed by unique count of users and sleep days. Great! Tableau has validated our calculation and informed us that there are no syntax issues! Let’s add it to the canvas. We have our aggregated result in one number! Notice that our new calculation can be found back in the Data Pane, marked with a little equal sign – this way you can find the calculations which are made by you, so not part of the original dataset. So, it seems that, on average, each user spends 328.8 minutes in bed per day. It would be more meaningful to express this in hours. We are not going to make another calculation for it. We could edit it by right-clicking on it in the data pane, but there is an easier way: Just double-click on the measure in canvas, and you can edit it. Let us divide by 60 and apply using Enter. Notice that this does not adapt your calculation in the data pane and only serves as an ad hoc calculation adaptation. Either way, we have what we wanted. So, on average, our participants spend 5.4 h in bed each day. Let’s format this number, and let’s visualize it by, for example, User Category. Mm.. It looks like our Busy mums are chronically short on sleep! Let us move our calculation to columns to visualize it as a bar chart and add labels to it. To estimate sleep efficiency, so a ratio of Time Asleep to Time in Bed, we still need two calculations. First, we need Average Minutes asleep per day per user, and the quickest way to do it is to duplicate my previous calculation, Time in Bed per day, and adapt it. Let’s go ahead, we will call it Minutes Asleep per day, and we will change the measure. Finally, we will make a quick ad hoc calculation in the Column itself by double-clicking on it and dropping two measures into it as a ratio. Enter.. and here is our result, the second measure being the ratio of minutes asleep to time in bed. So, it seems that our Busy mums aren’t, after all, the least efficient sleepers! Average Joes spend more time in bed but less time asleep. Interesting insight! Now on to you to calculate other cool metrics using Tableau.

2. Let's practice!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.