#### Overview of this book

Learning Tableau
Credits
www.PacktPub.com
Preface
Free Chapter
Creating Your First Visualizations and Dashboard
Working with Data in Tableau
Moving from Foundational to Advanced Visualizations
Using Row-level and Aggregate Calculations
Table Calculations
Formatting a Visualization to Look Great and Work Well
Telling a Data Story with Dashboards
Adding Value to Analysis – Trends, Distributions, and Forecasting
Making Data Work for You
Advanced Techniques, Tips, and Tricks
Index

## Visualizing data

A new connection to a data source is an invitation to explore. At times, you may come to the data with very well-defined questions and a strong sense of what you expect to find. Other times, you will come to the data with general questions and very little idea of what you will find. The data visualization capabilities of Tableau empower you to rapidly and iteratively explore the data, ask new questions, and make new discoveries.

The visualization examples in the following sections cover a few of the most foundational chart types. As you work through the examples, keep in mind that the goal is not simply to learn how to create each chart type. Rather, the examples are designed to help you think through the process of discovery, analysis, and storytelling. Tableau is designed to make this process intuitive, rapid, and transparent. Far more important than memorizing steps to create a bar chart is to understand how to use Tableau to create a bar chart and then iteratively adjust your visualization to gain new insight as you ask new questions.

### Bar charts

Bar charts visually represent data in a way that makes comparisons of a value across different categories easy to compare. Length is the primary means by which you will visualize the data. You may also incorporate color, size, stacking, and order to communicate additional attributes and values.

Creating bar charts in Tableau is very easy. Simply drag and drop the measure you want to see on either the Rows or Columns shelf and the dimension that defines the categories onto the opposing Rows or Columns shelf.

As an analyst for the coffee chain, you are ready to begin a discovery process focused on profit. Create a new sheet for this and every subsequent example in the workbook you started. This chapter's workbook will contain the complete examples, so you can compare your results.

Begin your analysis with the following steps:

1. Drag and drop the Profit field from Measures on the Data window on the left to the Columns shelf. You now have a bar chart with a single bar representing the sum of profit for all the data in the data source.

2. Drag and drop the Product Type field from Dimensions in the Data window to the Rows shelf. This slices the data to give you four bars, representing the sum of profit for each product type.

You now have a horizontal bar chart. This makes the comparison of profit between the product types easy. Notice how the mark type dropdown on the Marks card is set to Automatic and shows that Tableau has determined that bars are the best visualization given the fields you have placed in the view. As a discrete dimension, the Product Type field defines row headers for each product type in the data. As a continuous measure, the Profit field defines an axis that causes each bar to be drawn from 0 to the value of the total profit for each product type.

### Note

Typically, Tableau draws a mark (a bar, shape, circle, square, and so on) for every intersection of dimensional values in the view. In this simple case, Tableau draws a single bar mark for each dimensional value (Coffee, Espresso, Herbal Tea, and Tea) of Product Type. The type of mark is indicated and can be changed in the drop-down menu on the Marks card. The number of marks drawn in the view can be observed on the lower-left status bar.

Tableau draws different marks in different ways. For example, bars are drawn from 0 (or the end of the previous bar, if stacked) along the axis. Circles and other shapes are drawn at locations defined by the value(s) of the field defining the axis. Take a moment to experiment with selecting different mark types from the dropdown on the Marks card. Having an understanding of how Tableau draws different mark types will help you master the tool.

#### Extending bar charts for deeper analysis

Using the preceding bar chart, you can easily see that Coffee has more total profit than any other product type and Tea has less total profit than any other type. What if you want to further understand the profitability of product types in different markets?

Drag the Market field from Dimensions in the Data window to the left of the Product Type field that is already on the Rows shelf.

You still have a horizontal bar chart. But now you've introduced Market as another dimension that changes the level of detail in the view and further slices the aggregate value of profit. By placing Market before Product Type, you are able to easily compare sales for each product type within a given market.

Now you are starting to make some discoveries. For example, Coffee is making a bit more profit than any other product type in the East market but a bit less than other products in the West market.

Let's take a look at a different view using the same fields arranged differently.

Drag the Market field from the Rows shelf and drop it on the Color shelf.

Instead of a side-by-side bar chart, you now have a stacked bar chart. Notice how each segment of the bar is color-encoded by the Market field. Additionally, a color legend has been added to the workspace. You haven't changed the level of detail in the view, so the profit is still summed for every combination of market and product type.

### Note

The level of detail of a view is a key concept when working with Tableau. In most basic visualizations, the combination of values of all the dimensions in the view defines the lowest level of detail for that view. All measures will be aggregated or sliced by the lowest level of detail. In the case of most basic views, the number of marks (indicated in the lower-left status bar) corresponds to the number of intersections of dimensional values.

If, for example, Product Type is the only field used as a dimension, you will have a view at the product type level of detail and all measures in the view will be aggregated per product.

If Market is the only field used as a dimension, you will have a view at the market level of detail and all measures in the view will be aggregated per market.

If you use both Product Type and Market as dimensions in the view, you will have a view at the level of product type and market. All measures will be aggregated per unique combination of product type and market.

Stacked bars are useful when you want to understand part-to-whole relationships. Now it is easy to see what portion of total profit for each product type is made in each region. However, it is very difficult to compare the profit for most of the markets across product types. This is because, with the exception of West, every segment of the bar has a different starting place. It is interesting to note that there is no bar segment for South for the Tea product type.

Conclude this example with the following steps:

1. Experiment by dragging the Market field from Color to the other various shelves on the Marks card, such as Size, Label, and Detail. Observe that in each case, the bars remain stacked but are redrawn based on the visual encoding defined by the Market field.

2. Finally, drag the Market field off the shelf and drop it in a gray area on the workspace. This will remove that field from the view. You should now have a bar chart that looks like the very first one you created. Later, you'll be able to use this simple bar chart in an interactive dashboard.

3. Right-click on the tab labeled Sheet 1 at the bottom of the screen and rename the sheet `Profit by Product Type`.

4. From the File menu, select Save and save your workbook as `CoffeeChainAnalsyis.twb`.

### Tip

At the time of writing this, Tableau does not have an autosave feature. You will want to get into the habit of saving the workbook early and then pressing Ctrl + S or selecting Save from the File menu often to avoid losing your work.

### Line charts

Line charts connect related marks in a visualization to show movement or the relationship between connected marks. The position of the marks and lines that connect them are the primary means of communicating the data. Additionally, you can use size and color to visually communicate additional information.

The most common kind of line chart is a time-series. Time series show the movement of values over time. They are very easy to create in Tableau and require only a date and a measure.

Continue your analysis of coffee chain profit using the workbook you just saved:

1. Create a new worksheet by clicking on the new worksheet button immediately to the right of the Profit by Product Type tab at the bottom. You should now have a new, blank worksheet named Sheet 2 by default. If you accidentally create a new dashboard or story, you can delete it or use the undo button.

2. Rename the sheet to `Profit over Time` by right-clicking on the tab and selecting Rename or by double-clicking on the text of the tab.

3. Drag the Profit field from Measures to Rows. This gives you a single, vertical bar representing the sum of all profit in the data source.

4. To turn this into a time series, you must introduce a date. Drag the Date field from Dimensions in the Data window and drop it in Columns.

5. Tableau has a built-in date hierarchy and the default level of detail has given you a line chart connecting 2 years. Let's say you want to see the profit by month. Right-click on the YEAR(Date) field in Columns and select Month from the second set of dates. Future chapters will discuss the details of the various date options.

### Tip

You can right-click drag and drop a date field as a shortcut to selecting the date option available from this menu. Right-click dragging and dropping other types of fields is a shortcut to quickly selecting other customizations, such as the type of aggregation. If you are using Tableau on a Mac, the equivalent is Option + left-click + drag and drop.

You now have a time series that shows you the profit for each month.

#### Extending line charts for deeper analysis

Right now, you are looking at the overall profit over time. Let's perform some analysis at a slightly deeper level:

1. Drag the Market field from Dimensions to Color. Now, you have a line per market with each line in a different color and a legend indicating which color is used for which market. As with the bars, adding a dimension to Color splits the marks. However, unlike the bars where the segments were stacked, the lines are not stacked. Instead, the lines are drawn at the exact value for the sum of profit for each market and month. This allows an easy and accurate comparison.

2. Drag the Product field from Dimensions and drop it directly on top of the Market field currently in the Marks card. This replaces the Market field with Product. You now have 13 overlapping lines. Often, you'll want to avoid more than two or three overlapping lines. However, note that you can enable highlighting on the color legend using the icon in the upper-right section of the legend. Then, clicking on a product in the color legend will highlight the associated line in the view. This can be a good way to pick out a single item and compare it with all others.

3. Hold down the Ctrl key and then drag the Product field from Color in the Marks card and drop it in Rows. This copies the field in the view and you now have a line chart for each product. Now you have a way to compare each product over time without overwhelming the overlap. This is the start of a spark-lines visualization that will be developed more fully when advanced visualizations are discussed.

4. Remove the Product field from the Rows shelf to return to the first time series created in this exercise. Additionally, you may experiment with the undo button in the toolbar.

### Geographic visualizations

Tableau makes creating geographic visualizations very easy. The built-in geographic database allows any field recognized as playing a geographic role to define a latitude and longitude. This means that even if your data does not contain latitudes and longitudes, Tableau will provide them for you based on fields such as Country, State, City, or Zip Code. If your data contains Latitude and Longitude fields, you may use them instead of the generated values.

### Tip

Although most databases do not strictly define geographic roles for fields, Tableau will automatically assign geographic roles to fields based on the field name and a sampling of values in the data. You can assign or reassign geographic roles to any field by right-clicking on the field in the Data window and using the Geographic Role option. This is also a good way to see what built-in geographic roles are available.

The power and flexibility of Tableau's geographic capabilities as well as the options for customization will be covered in more detail in Chapter 10, Advanced Techniques, Tips, and Tricks. In the following examples, we'll consider some of the foundational concepts of geographic visualizing.

Geographic visualization is incredibly valuable when you need to understand where things happen and if there are any spatial relationships within the data. Tableau offers two basic forms of geographic visualization:

• Filled maps

• Symbol maps

#### Filled maps

Filled maps, as the name implies, make use of filled areas, such as the country, state, county or zip code, to show the location. The color that fills the area can be used to encode values of measures or dimensions.

What if you want to understand profit for your coffee chain and see whether there are any patterns geographically? Let's take a look at some examples of how you might do this:

1. Create a new sheet and name it `Profit by Location`.

2. Double-click on the State field in the Data window. Tableau automatically creates a geographic visualization using the Latitude (generated), Longitude (generated), and State fields.

3. Drag the Profit field from the Data window and drop in on the Color shelf in the Marks card. Based on the fields and shelves you've used, Tableau has switched the automatic mark type to filled maps.

The filled map fills each state with a single color to indicate the relative sum of profit for each state. The color legend, now visible in the view, gives the range of values and indicates that the state with the least profit had a total of \$799 and the state with the most profit had a total of \$31,785.

You may observe that not all states are shown. Tableau will only draw a geographic mark, such as a filled state, if it exists in the data and is not excluded by a filter. There were only 20 states in the data and therefore, there are only 20 filled states. The rest of the map is a background image.

Filled maps can work well in interactive dashboards and have quite a bit of aesthetic value. However, certain kinds of analyses are very difficult with filled maps. Unlike other visualization types where size can be used to communicate facets of the data, the size of a filled geographic region only relates the geographic size. For example, which state has the highest profit? You might be tempted to say California, but are you sure that's not just because it is larger than Illinois? Which has more profit: Massachusetts or Texas? Use filled maps with caution and consider pairing them with other visualizations for clear communication.

#### Symbol maps

The other standard type of geographic visualization available in Tableau is a symbol map. Marks on this map are not drawn as filled regions; rather, marks are shapes or symbols placed at specific geographic locations. Size, color, and shape may also be used to encode additional dimensions and measures.

Continue your analysis using the `Profit by Location` sheet you developed previously:

1. Drag Area Code from Dimensions to the Detail shelf on the Marks card. Tableau automatically switches to a symbol map and draws a circle at the latitude and longitude of each area code.

2. Drag Sales from Measures to the Size shelf on the Marks card. At this point, you have color encoded by profit and size encoded by sales. This allows some very useful analysis, as you can immediately identify areas with high sales and low profit. Profit may not have been as useful on the Size shelf because it can have negative values and there is no way to visually represent a negative size.

### Tip

You can improve upon the default view. Click on the Color shelf and set the transparency to somewhere between 50 percent and 75 percent. Additionally, add a dark border. This makes the marks stand out and you can better discern any overlapping marks.

Unlike filled maps, symbol maps allow you to use size to visually encode aspects of the data. Symbol maps also allow greater precision. In fact, if you have latitude and longitude in your data, you can very precisely plot marks at a street address level of detail. This type of visualization also allows you to map locations that do not have clearly defined boundaries. Note that if you were to change the mark type from Automatic to Filled Map in the view, you would get an error message indicating that filled maps are not supported at the level of detail in the view.

### Using Show Me

Show Me is a powerful component of Tableau. The Show Me toolbar displays small thumbnail images of different types of visualizations, allowing you create visualizations with a single click. Based on the fields you select in the Data window and the fields that are already in the view, Show Me will enable possible visualizations and highlight a recommended visualization. Explore the features of Show Me by following these steps:

1. Create a new worksheet in the workbook and name it `ShowMe Example`.

2. If the Show Me window is not expanded, click on the Show Me button in the upper-right section to expand the window.

3. Press and hold the Ctrl key while clicking on the Area Code, State, and Profit fields in the Data window to select each of these fields.

Observe that the Show Me window has enabled certain visualization types, such as text tables, heat maps, symbol maps, filled maps, and bar charts. These are the visualizations that are possible given the fields already in the view in addition to any fields selected in the data window. Show Me also gives a description of what fields are needed for a given visualization type. Symbol maps, for example, require one geographic dimension and up to 2 measures.

Other visualizations are grayed out, such as line charts and histograms. These visualization types cannot be created with the fields that are currently in the view and selected in the Data window. Hover over the grayed out line charts in Show Me. Show Me indicates that line charts require one or more measures, which you have selected, but also require a date field, which you have not selected.

### Tip

Tableau will actually draw line charts with fields other than dates. Show Me gives you options for what is typically considered good practice for visualizations. Understanding how Tableau renders visualizations based on fields and shelves instead of always relying on Show Me will give you much greater flexibility in your visualizations. At the same time, you will need to cultivate an awareness of good visualization practices.

Finally, note that with Area Code, State, and Profit selected, the symbol map has a blue border in the Show Me window. Show Me indicates the symbol map as most likely the best visualization for the selected fields.

Show Me can be a powerful way to quickly iterate through different visualization types as you search for insight into the data. However, as a data explorer, analyst, and storyteller, you should consider Show Me as a helpful guide that gives suggestions. You may know that a certain visualization type will answer your questions more effectively than the suggestions from Show Me. You may have a plan for a visualization type that will work well as part of a dashboard but isn't even included in Show Me.

### Tip

You will be well on your way to learning and mastering Tableau when you can use Show Me effectively, but feel just as comfortable building visualizations without it. Show Me is powerful to quickly iterate through visualizations as you look for insight and raise new questions. It is useful to start with a standard visualization that you will further customize. It is wonderful as a teaching and learning tool.

Be careful not to use it as a crutch without understanding how visualizations are actually built from the data. Take time to evaluate why certain visualizations are or are not possible. Pause to see what fields and shelves were used when you selected a certain visualization type.

Conclude the Show Me example by following these steps:

1. Experiment with Show Me by clicking on various visualization types, looking for insight into the data that may be more or less obvious with different ways of visualizing the data. Circle views and box-and-whisker-plots show the distribution of area code for each state. Bar charts easily expose several area codes with negative profit.

2. Right-click on the current Show Me Example sheet tab at the bottom and select Delete Sheet.