Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Data Modeling with Tableau

You're reading from   Data Modeling with Tableau A practical guide to building data models using Tableau Prep and Tableau Desktop

Arrow left icon
Product type Paperback
Published in Dec 2022
Publisher Packt
ISBN-13 9781803248028
Length 356 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Kirk Munroe Kirk Munroe
Author Profile Icon Kirk Munroe
Kirk Munroe
Arrow right icon
View More author details
Toc

Table of Contents (22) Chapters Close

Preface 1. Part 1: Data Modeling on the Tableau Platform
2. Chapter 1: Introducing Data Modeling in Tableau FREE CHAPTER 3. Chapter 2: Licensing Considerations and Types of Data Models 4. Part 2: Tableau Prep Builder for Data Modeling
5. Chapter 3: Data Preparation with Tableau Prep Builder 6. Chapter 4: Data Modeling Functions with Tableau Prep Builder 7. Chapter 5: Advanced Modeling Functions in Tableau Prep Builder 8. Chapter 6: Data Output from Tableau Prep Builder 9. Part 3: Tableau Desktop for Data Modeling
10. Chapter 7: Connecting to Data in Tableau Desktop 11. Chapter 8: Building Data Models Using Relationships 12. Chapter 9: Building Data Models at the Physical Level 13. Chapter 10: Sharing and Extending Tableau Data Models 14. Part 4: Data Modeling with Tableau Server and Online
15. Chapter 11: Securing Data 16. Chapter 12: Data Modeling Considerations for Ask Data and Explain Data 17. Chapter 13: Data Management with Tableau Prep Conductor 18. Chapter 14: Scheduling Extract Refreshes 19. Chapter 15: Data Modeling Strategies by Audience and Use Case 20. Index 21. Other Books You May Enjoy

Shaping data for Tableau

In the previous section, we looked at the data format that works best in Tableau. We will now look at one of the two main examples where data is shaped ineffectively for Tableau and how we can easily change it to the correct format before beginning our data analysis.

Time-based data, especially financial data, is often stored in Excel with the dates in the column headers, the fields spread across columns in the first row, and values falling in the cells in the intersection. We can see this in Figure 1.6. This is a planning sheet for sales targets for the year 2022 for category sales of our SuperStore data:

Figure 1.6 – SuperStore sales targets format

Figure 1.6 – SuperStore sales targets format

If we connect this data to Tableau, it gives us the following metadata:

Figure 1.7 – SuperStore target default metadata

Figure 1.7 – SuperStore target default metadata

Thinking back to having fields in columns, a field type, and values in rows, we can see that this interpretation of the data is not helpful at all. What we want are three fields of the following types:

  • Date: Type – date. There are 12 values, one for each month in 2022.
  • Category: Type – string. There are three values: Furniture, Office Supplies, and Technology.
  • Revenue target: Type – whole number

In order to get these fields into the right format, we need to pivot those date columns into rows and then rename two fields. Tableau makes this easy for us. Here are the steps:

  1. Open Tableau Desktop.
  2. Click on the Connect to Data blue hyperlink near the top left-hand side of the Tableau Desktop UI.
  3. Choose Microsoft Excel. Navigate to the SuperStore 2022 Budget.xlsx file in the location you saved it on your computer. Click Open.
  4. You will be presented with a screen similar to Figure 1.6.
  5. In the Table Details pane, click on the header of Jan-22, hold down the Shift key, and click on the Dec-22 header to select all the date columns. You might find this easier if you first collapse the metadata pane:
Figure 1.8 – Multiselecting columns in the Table Details pane

Figure 1.8 – Multiselecting columns in the Table Details pane

  1. Hold your cursor over the top-right-hand corner of the Dec-22 header to bring up the down arrow.
  2. Click on the down arrow to bring up the menu of options. Choose Pivot.
Figure 1.9 – Menu options from the Table Details pane

Figure 1.9 – Menu options from the Table Details pane

  1. You will now be presented with three fields. We are almost there!
Figure 1.10 – Table Details after the pivot

Figure 1.10 – Table Details after the pivot

  1. Our last step is to rename our three fields. We can do this by clicking on the field name and typing over the ones that are there, or by clicking on the same down arrow that we used in step 8 and using the Rename option.
  2. Let’s rename our fields as follows: F1 to Category, Pivot Field Names to Date, and Pivot Field Values to Sales Target:
Figure 1.11 – Table details after renaming

Figure 1.11 – Table details after renaming

  1. Our last step is making sure our field types are correct. Category is a string field (alphanumeric) so it should show Abc, which it does. Similarly, Sales Target is a number and Tableau has it correct. Date is showing as a string. We would really like this as a date field because Tableau has special date-handling capabilities to make analysis much easier for us. To change the Date field to a type of date, click on Abc over Date and change the field type to Date:
Figure 1.12 – Table details – changing the data type

Figure 1.12 – Table details – changing the data type

Don’t close this workbook; we will pick up from this point in the exercise in the next section, where we will combine data to our data model from other tables.

In this section, we looked at how we may need to reshape our data to make better data models in Tableau. In the next section, we will look at a use case where we need to add additional columns (fields) of data from other data sources to our model.

You have been reading a chapter from
Data Modeling with Tableau
Published in: Dec 2022
Publisher: Packt
ISBN-13: 9781803248028
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image