In the first recipe, we specified communication as one of the key features of a dashboard. We need to be able to share the right information with the right audience, at the right time, to the right people, and in the right format.
Sometimes, data needs to be translated so that it matches the business rules and the business understanding of the organization. Tableau offers a number of different ways that help you translate data into something that the business decision makers will understand.
Grouping is one way of making data meaningful to the business. In this recipe, we will look at grouping some dimension members into a single member. Rolling up some of the members in one dimension is a good way of summarizing data for dashboards.
In this recipe, we will look at grouping dimension members; then, we will look at more complex grouping of calculations. The business question is an investigation into the characteristics of customers, for example, those who have children, and those who do not. We will group the NumberChildrenAtHome dimension members into the group of customers who have children and those who do not.
Then, we will look at a more advanced example of grouping the data by measure rather than dimension. To do this, we can create a calculation that will distinguish the values that are below the average sales amount and above the average. Results that are classified as above average are labelled Above or Equal to Average, and below average sales are labelled Below Average. We can then use this calculation to convey a visual message to the business user; for example, we could color the above average sales in one color and the below average sales in another in order to make the distinction easily identifiable.
DimCustomer.xls
and import it into Tableau's internal data store mechanism. To do this, navigate to Data | Connect to Data.DimCustomer.csv
file and select it.Connection_DimDate
.NumberOfRecords
column. You can see an example in the next screenshot.CustomersWithChildren
, and click on OK.Customers with No Children
.Customers With Children
so that it matches the format used elsewhere. To do this, select the numbers 1 to 4 in the table and right-click on them.Customers With Children
and click on OK.Chapter 2
workbook and continue to work in the existing worksheet.
SalesAboveOrBelowAverage
.IF ( SUM([SalesAmount]) - WINDOW_AVG(SUM([SalesAmount]), First(), Last() ) < 0 ) Then 'Below Average' Else 'Above or Equal To Average' END
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
To summarize, we have created a calculation that is meaningful to a business user. It provides the color display of the measure, which helps the business user understand things more efficiently. To summarize, it is simple and effective to conduct a grouping of dimension members into a binary grouping. This is useful for dashboards in order to provide an "at a glance" metric visualization that shows the organization has more customers who do not have children than those who do.
Essentially, this formula uses the WINDOW_AVG
function to work out the average of the values that are in the Tableau view of the data. Basically, this average works out the value of the data that is viewable in the Tableau canvas and does not include data that has been filtered.
It uses First()
and Last()
to work out the average of all the data from the first row right until the last row. The calculation takes the current SalesAmount value and compares it with the average SalesAmount value.
Tableau allows you to group data together by simply arranging fields of your data source on a Tableau worksheet.
When you group fields in a worksheet, Tableau queries the data using standard drivers and query languages (such as SQL and MDX). It then groups data together wherever necessary. Finally, it presents a visual analysis of the data.