Tableau Customer Conference 2013 Table Calculation Fundamentals Jazmyn Li and Robert DuPont 1 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Example 1.1: simple quick table calculation: percent of total This aims to show attendees where they can find table calculations to perform common business analysis. Data source: Step 1: SAT Math Scores by College 1. Right click and drag [SAT Math Scores] from Measures pane, and place it on Rows shelf. Point out right click and drag will show different aggregation option/date hierarchy option in a window. 2. Select CNT([SAT Math Scores]). Drag [SAT Math Score (bin)] on to Columns shelf. 3. Click on icon to show label. Step 2: 1. Click on CNT[SAT Math Scores], 2. Hover over Quick Table Calculation, and show all menu items. 3. Select Percent of Total 2 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Example 1.2 This view shows how to use multiple quick table calculations in a single view, with dual axis chart, multiple mark types, and secondary calculation. Step 1 1. Right click and drag [SAT Math Scores] to Rows shelf, and select CNT([SAT Math Scores]) 2. Select the third Marks card pointing out multiple Marks card feature. 3. Select Line in the drop down menu. Point out the change in mark type symbol on each Marks card. Also point out: difference between table calculations and other aggregations, delta/triangle on the pill. 3 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Step 2: 1. Select click on second CNT([SAT Math Scores]) 2. select Running Total from Quick Table Calculation menu. 3. In the same menu, select Edit Table Calculation. Step 3: 1. check Perform a secondary calculation on the result. 2. Select Percent of Total from drop down menu of Secondary Type 4 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Step 4: in the drop down menu of the second CNT([SAT Math Score]), select dual axis. Make sure the second Marks card has the mark type of bar Explain the view: shows how much of the sample scores in the range, and what percentile it is relevant to other bins. 5 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Exercise 1 6 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Step 1: drag SUM([Sales]) on to Rows, right click drag [Order Date] on to Columns. Select continuous MONTH(Order Date) Step 2: duplicate SUM([Sales]), either Ctrl and drag or drag another SUM([sales]) on to Row. On the second SUM([Sales]) pill, select Moving Average under Quick Table Calculation 7 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Step 3: edit table calculation There are a few ways to do a 6-month moving average. Goal is for previous value (0-6) + next value (0-6) + current value (0-1) = 6 Example shown is 5 previous values plus the current value Step 4: click on second pill of SUM([Sales]), select dual axis. Right-click on the axis on the right, select Synchronize Axis and uncheck Show Header 8 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Table calculations provide a great way to increase the value of your data in Tableau. Table calculations are computations that are applied to all values in a table, and are often dependent on the table structure itself. Table Calcs can be easy, but depending on your analysis there is a possibility they could become complicated. The best way to learn them is by starting with the “Quick Table Calculations”! Start by dragging a dimension to the Rows shelf Then Drag a measure to the Columns Shelf Right click on the measure and select “Quick Table Calculation” Start with the first option, “Running Total” 9 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots It is possible to change the way a table calculation is calculated because they depend on the results in the table. Take this example: Notice that the default is set to Table (Across) which indicates that we are addressing to compute along the entire table, moving horizontally through each partition. Because we are addressing across, the columns (Year and Quarter) are the fields that we are partitioning by. 10 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Now let's look at some other ways we can address our table calculation. Click on the pill and select Compute Using and change the selection to Table (Down). Table (Down) indicates that we are addressing to compute vertically through each partition of the table. Because we are addressing down, the rows (Product type and Market) are the fields that we are partitioning by. 11 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Click on the pill and select Compute Using and change the selection to Table (Across then Down). Table (Across then Down) indicates that we are addressing to compute across the table horizontally and down the table vertically. Because we are addressing all columns and rows, the entire table is the partition. 12 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Click on the pill and select Compute Using and change the selection to Pane (Across). Pane (Across) indicates that we are addressing to compute across the pane horizontally. However, fields that separate the panes are now partitioning fields. In this case, Market has become a partitioning field. 13 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Click on the pill and select Compute Using and change the selection to Cell. Cell indicates that we are addressing the individual cells in the table, and all fields in the view become partitions. These types of calculations are most useful when computing a Percent of Total. 14 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Exercise 2: Table Calculation Take our previous examples, instead of finding the percent of total; I want to find the Percent Difference from the previous quarter in the table. **Bonus - find the percent difference from Q1-2012. 15 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Solution: Step 1: 1. Select the Sum([Sales]) pill on the marks card, and go to Add Table Calculation. Add a Percent Difference. 2. Then select the pill again and select Compute Using -> Table (Down). **Bonus, select the pill again and select Relative To > First. 16 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Table calculations: RUNNING_MAX() 17 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Drag [Sales] on to Rows Right click drag [Order Date] onto Columns Select continuous MONTH(Order Date) 18 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Create a calculated field, either through Analysis > Create a calculated field, or right click in data pane Type in SUM([Sales]) = RUNNING_MAX(SUM([Sales]) Title the calculation field: color-max profit 19 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots It is also possible to write calculated fields that include table calculations. Let’s review some of the syntax that can be used for them. Helper Functions • First () • Last () • Index () • Size () Primary Functions • Total • Lookup • Window Running • Previous Value 20 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Exercise 3: Max Profit In this view I'd like to show the points on the chart where we had record monthly profits. How would we use a table calculation to accomplish this? Hint: Use dual axis, and a table calculation! Ready, and go! 21 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Solution: Step 1. Drag another Profit pill to the Rows Shelf, select the second pill and make it a Dual Axis. 22 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Step 2. Leave the previous Sum([Profit]) set to a Line chart, but change the new Sum([Profit]) to have Circles for the marks. 23 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Step 3. Create a new calculated field, call it New Record. The equation to call out the profitable records is IF SUM(Profit)>PREVIOUS_VALUE(0) THEN SUM(Profit) ELSE PREVIOUS_VALUE(0) END. 24 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Step 4. At this point we need to write a new calculation in order to represent this as colors on our viz. Create a new Calculated field and call it New Record KPI. The calculation is IF [New Record] = SUM(Profit) THEN "Record Profits" ELSE "Normal Profits" END 25 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Step 5. Place the final New Record KPI on the color shelf of the second/circle Sum([Profit]). 26 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Exercise 3: Summary Card The summary card is not available on Tableau Server, but I would like to find a way to include the information. I think the best place for it would be the tool tip that appears when hovering over a mark. Hint: Use multiple Table Calculations. 27 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Solution: Step 1. Create a Calculated Field for each value on the summary card. For example, the Window_Count(Sum(Sales)) for count; the Window_AVG(Sum(Sales)) for Average and so forth. 28 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots 1. Calculations continued 29 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Step 2. Once all of the calculated fields are created, place them in the Level of Detail in the marks card. 30 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Step 3. Next, select the Tooltip icon in the marks card and clear the current selection. Step 4. Use the Insert dropdown to add in the values of the calculated fields and give corresponding labels to each. 31 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Exercise 4: Rank by Profit or Sales In this example I would like to be able to sort my view by either Sales or Profit via a Parameter. 32 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Step 1. Create two calculated fields called Profit Rank & Sales Rank. Both will have the same equation: Index(). 33 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots 2. Right click on each calculated field in the measure pane and convert each to Discrete. Add both fields the Rows shelf. 34 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Step 3. For Profit Rank, right click on the pill and select Edit Table Calculation. In the Compute Using dropdown select Advanced. In the new window add Sub-Category to the addressing field and change the Sort to Descending by Sum of Profit. 35 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Step 4. For Sales Rank, repeat the steps from Profit Rank, but instead of sorting by Descending by Sum of Profit sort by Descending by Sum of Sales. Step 5. To add these into a parameter, right click in a blank area of the Measures Pane and select Create Parameter. Call it "Choose Rank" and change the data type to a string. Next change Allowable Values to List and insert "Profit Rank" and "Sales Rank" as list values. Select "OK". 36 INTERNAL ONLY – Copyright 2013 Tableau Software Click Steps Screenshots Step 6. Next, create a calculated field called Master Rank and write the equation: Case [Choose rank] When "Sales Rank" then [Sales Rank] When "Profit Rank" then [Profit Rank] End 7. Change this field to be discrete and add it to the view. 37 INTERNAL ONLY – Copyright 2013 Tableau Software Table Calculation Fundamentals Jazmyn Li and Robert DuPont 38 INTERNAL ONLY – Copyright 2013 Tableau Software