Extending the data / Rental Calendar
Last updated
Last updated
Often, there will be dimensions or measures you’d like to have in your data, but that are not present in the source. Many times, you will be able to extend your dataset using calculated fields. We already considered an example of creating a field for the full name of the guest where we only had first and last name fields.
Another piece of data that might unlock some truly interesting analysis would be the length of each rental. We have the start and end dates, but not the length of time between those two dates. Fortunately, this is easy to calculate.
Create a calculated field named Nights Rented
with the following code:
Tableau employs intelligent code completion. It will offer suggestions for functions and field names as you type in the code editor. Pressing the Tab key will autocomplete what you have started to type based on the current suggestion.
Figure 4.16: The intelligent code completion will suggest possible field names and functions as you type
The DATEDIFF()
function takes a date part description, a start and an end date, and returns a numeric value for the difference between the two dates. We now have a new measure that wasn’t available previously.
We can use this new measure in our visualizations, such as the Gantt chart of rentals, as follows:
Figure 4.17: The calculated field allows us to create the Gantt chart
You’ll find many ways to extend your data with calculations as you continue your journey in Tableau. And that will enable you to accomplish some amazing analyses and visualizations. We’ll consider some examples next.