Extending the data

Often, there will be dimensions or measures you'd like to have in your data, but which 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.

Additionally, one thing that might unlock some interesting analysis, is to calculate 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 Days Rented with the following code:

DATEDIFF('day', [Start Date], [End Date])
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.

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, which wasn't available previously. We can use this new measure in our visualizations, such as the Gantt chart of rentals, as follows:

The chart allows us to instantly understand how long each guest stayed, when the rooms were occupied, and when the rooms were vacant.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.97.120