Dynamic measure swap in Tableau - Real Business Scenario
Start learning this pattern below
Jump into concepts and practice - no test required
| Date | Region | Product Category | Total Sales | Profit | Quantity Sold |
|---|---|---|---|---|---|
| 2024-01-01 | North | Electronics | 10000 | 2500 | 150 |
| 2024-01-01 | South | Furniture | 8000 | 1200 | 100 |
| 2024-02-01 | North | Electronics | 12000 | 3000 | 180 |
| 2024-02-01 | South | Furniture | 7000 | 1000 | 90 |
| 2024-03-01 | North | Electronics | 15000 | 4000 | 200 |
| 2024-03-01 | South | Furniture | 9000 | 1500 | 110 |
| 2024-04-01 | North | Electronics | 13000 | 3500 | 170 |
| 2024-04-01 | South | Furniture | 8500 | 1300 | 105 |
No formula needed; just connect and import the data.Parameter configuration: Name='Select Measure', Data type=String, Allowable values=List, Values=['Total Sales', 'Profit', 'Quantity Sold'], Current value='Total Sales'.IF [Select Measure] = 'Total Sales' THEN SUM([Total Sales]) ELSEIF [Select Measure] = 'Profit' THEN SUM([Profit]) ELSE SUM([Quantity Sold]) ENDDrag 'Date' to Columns shelf, drag 'Dynamic Measure' to Rows shelf, set 'Date' to continuous month.Right-click 'Select Measure' parameter and choose 'Show Parameter Control'.Date | Dynamic Measure (Selected) ---------------------------------------- 2024-01 * 2024-02 * * 2024-03 * * * 2024-04 * * * = Value points on line chart User selects measure from dropdown: Total Sales, Profit, or Quantity Sold Chart updates accordingly.
Add a second parameter to select Region and update the chart to show the selected measure for the chosen region only.
Practice
What is the main purpose of using a dynamic measure swap in Tableau dashboards?
Solution
Step 1: Understand dynamic measure swap concept
Dynamic measure swap allows users to select which measure they want to see on one chart instead of showing all measures separately.Step 2: Identify the main benefit
This makes dashboards interactive and saves space by avoiding multiple charts for each measure.Final Answer:
To let users choose which measure to display on a single chart -> Option CQuick Check:
Dynamic measure swap = user chooses measure [OK]
- Thinking it creates multiple charts instead of one
- Confusing it with data refresh or filtering
- Assuming it changes data source connections
Which Tableau feature is essential to create a dynamic measure swap?
Choose the correct syntax to define it.
CASE [Parameter]
WHEN 'Sales' THEN SUM([Sales])
WHEN 'Profit' THEN SUM([Profit])
ENDSolution
Step 1: Identify the syntax used
The code uses a CASE statement with a parameter to choose between measures like Sales and Profit.Step 2: Match feature to syntax
This is the standard way in Tableau to create dynamic measure swap by switching measures based on parameter value.Final Answer:
Parameter with CASE statement to switch measures -> Option AQuick Check:
CASE + Parameter = dynamic measure swap [OK]
- Using IF without parameter for swapping
- Confusing filters or dashboard actions with measure swap
- Ignoring the need for a parameter
Given the parameter [Select Measure] with values 'Sales' and 'Profit', and the calculated field:
CASE [Select Measure]
WHEN 'Sales' THEN SUM([Sales])
WHEN 'Profit' THEN SUM([Profit])
ENDWhat will be the result if the parameter is set to 'Profit' and the total profit is 5000?
Solution
Step 1: Understand parameter value effect
The parameter is set to 'Profit', so the CASE statement returns SUM([Profit]).Step 2: Calculate output based on data
Since total profit is 5000, the calculated field returns 5000.Final Answer:
5000 -> Option DQuick Check:
Parameter 'Profit' returns SUM([Profit]) = 5000 [OK]
- Thinking missing ELSE causes error (it returns NULL instead)
- Confusing measure names with values
- Assuming default is zero without ELSE
Identify the error in this dynamic measure swap calculated field:
CASE [Measure Selector]
WHEN 'Sales' THEN SUM(Sales Amount)
WHEN 'Profit' THEN SUM(Profit Margin)
ENDSolution
Step 1: Check field name syntax
In Tableau, field names must be enclosed in square brackets, e.g., [Sales Amount], [Profit Margin].Step 2: Identify error in code
The code uses SUM(Sales Amount) and SUM(Profit Margin) without brackets, causing syntax error.Final Answer:
Missing square brackets around field names -> Option AQuick Check:
Field names need [ ] in SUM() [OK]
- Omitting brackets around field names
- Assuming CASE syntax is wrong
- Thinking SUM can't be inside CASE
You want to create a dashboard where users can switch between SUM([Sales]), AVG([Profit]), and COUNT([Orders]) using one parameter called [Measure Choice]. Which calculated field correctly implements this dynamic measure swap?
?Solution
Step 1: Check parameter values and measures
The parameter has three values: 'Sales', 'Profit', and 'Orders'. Each must map to the correct aggregation.Step 2: Verify calculated field syntax
CASE [Measure Choice] WHEN 'Sales' THEN SUM([Sales]) WHEN 'Profit' THEN AVG([Profit]) WHEN 'Orders' THEN COUNT([Orders]) END uses CASE with explicit WHEN for all three values and correct aggregations, matching the parameter choices exactly.Final Answer:
CASE [Measure Choice] WHEN 'Sales' THEN SUM([Sales]) WHEN 'Profit' THEN AVG([Profit]) WHEN 'Orders' THEN COUNT([Orders]) END -> Option BQuick Check:
CASE with all WHENs matches parameter values [OK]
- Using ELSE instead of explicit WHEN for all options
- Using SWITCH which is not valid in Tableau
- Mixing IF and CASE syntax incorrectly
