Tableau for Beginners (session 4)

Tableau
beginner
Published

November 21, 2024

Warning

This is currently a draft version of the materials for this training session, and so may contain minor errors and inaccuracies.

No feedback found for this session

Session outline

  • In this session, we’re going to build out the GP practice size dashboard from last time
  • we’re going to use some new features of Tableau to help us with that
    • Calculated Fields
    • Table calculations
    • Level of Detail (LOD) expressions

Session files

Getting started

Task
  • find your dashboard from last time
    • or create a new dashboard based on the following four data sources for this week
      data structure
  • create a new, empty, worksheet

Calculated Fields

  • Calculated Fields are the basic tool used to summarize data in Tableau
  • let’s start with a simple example: how big is the largest GP practice?
  • we’ll answer that by writing a simple formula: MAX([Practice List Size])
    • MAX is a function that finds the largest value in some data
    • [Practice List Size] refers to one of our columns of data

MAX()

Task
  • right-click your Practice List Size field, and select Create > Calculated Field...
    select Create > Calculated Field…
  • name your Calculated Field largest_practice
  • then use the following (case sensitive) formula to calculate the largest practice: MAX([Practice List Size])
    Calculate the largest practice

Finding your calculated fields

  • note that your new largest_practice field will show up at the very bottom of your sets of data:
    Calculated field location
  • note too the equals sign in the icon, indicating a calculated field

MIN()

Task
  • now repeat to find the smallest practice using MIN()
    Smallest practice

COUNT()

Task
  • now repeat to find the number of practices using COUNT()
    Number of practices

AVG()

Task
  • finally, find the average practice size using AVG()
    Average practice size

Adding calculated fields to worksheets

Task
  • Drag any one of your new calculated fields to Text Marks, then add HB Name to the column shelf:
    Adding calculated fields to a worksheet

  • then (in a slightly quirky way) you should be able to add each calculation by double-clicking the name of the calculated field:
    Double-click the calculated field to add to the worksheet

Finding functions

  • from the right-click menu, you can edit calculations
    edit calculations
  • note that the right-hand edge of the calculation interface contains a mini help section for the available functions
    Available functions

Combining functions

  • we can use several functions in a formula to do interesting analytic work
  • we’ll look at three helpers for combining functions:
    • brackets
    • +
    • STR()

Brackets

  • you can combine several functions together with brackets
  • the functions will run from the inside-out:
    • ROUND(AVG([dat])) will:
      • average [dat], then
      • round that result
Task
  • try making a rounded average of practice list size to the nearest 100
  • ROUND(AVG([Practice List Size]), -2)

+

  • + joins text values together
Task
  • create a new sheet with HB Name on the Rows shelf
  • then create a new calculation with the formula "The first practice name is " + MIN([GP Practice Name])
  • add that calcuation to Text Marks
  • you may need to play with the Fit menu to see your results:
    The Fit menu

STR()

  • if you try to use + to add text to numeric calculations, you’ll run into a problem
  • STR() converts numbers to text
Task
  • try "The smallest practice has " + STR(MIN([Practice List Size])) + " patients"

IF and friends

  • IF something THEN action1 ELSE action2 END
  • ELSEIF something else THEN action2
  • IFF(something, action1, action2)

Table calculations

  • Table calculations are calculations on visualizations, rather than the underlying data
  • We’ll run through a quick table calculation now

Quick table calculations

Task
  • build a new sheet with largest and smallest practices by board
    largest and smallest practices by board
  • right-click your largest_practice calculation, and select Quick Table Calculation > Rank
    Quick Table Calculation
  • that converts largest_practice to display as a rank between 1 and 14
  • clear the table calculations from the right-click menu:
    clear the table calculations

Level of detail calculations

  • LoD calculations allow you to control the level of detail that your calculations work at
  • this is just a taster as this gets into advanced (and messy) territory pretty fast
Task
  • create a table showing the average of each demographic group per NHS board:
    average of each demographic group per NHS board
  • now add a LoD calculation that will show the average for each attribute bracket for Scotland overall using {FIXED [Attribute] : AVG([Value])}:
    average for each attribute bracket for Scotland overall

That gives us a slightly messy way of benchmarking our average for our bracket within a board to the bracket nationally:
national benchmark

We could also try the more ambitious:

AVG([Value]) / ATTR({FIXED [Attribute] : AVG([Value])})

(you need the ATTR function to trick Tableau into mixing and matching these different values)