How to Switch Metrics (or Dimensions) Using Set Actions

I previously wrote about how to change dimensions using set actions. However, I have since found a better, easier way that can work for metrics OR dimensions. Previously, you had to unselect a value before selecting the next. This method does not require that!

Click to View on Tableau Public

This can be extended even further to add text for additional insight or information. I then used transparent worksheets to add a trend line of each metric to create a custom button for each metric:

This methodology can also be used to swap worksheets, as Matt Chambers demonstrates on his blog.

How To

  1. Determine which metrics (or dimensions) to use. I am going to use profit, quantity, sales, and discount.
  2. Find any dimension that has equal or more values. For example, region has four values, east/west/south/central. Since I have four metrics I want to use, this will work out! The way this method works is that selecting the east region will correspond to one metric, the west will correspond to another metric, etc.
  3. Create a new set on the selected dimension, region. This can be done by right clicking on the desired dimension (ex: region) and selecting create > set. Name the set “Metric” and select a value of “East”
  4. Create a new calculation called Metric Calc. Here we will assign each metric to the specified region. The part after the case statement is how we determine what value is in the set.
    case {MIN(if [Metric] then [Region] END)}
    when "Central" then [Sales]
    when "East" then [Profit]
    when "South" then [Quantity]
    when "West" then [Discount]
  5. Create a new calculation called Metric Calc Label. This will serve as a way to rename the regions to the proper metric name
    case [Region]
    when "Central" then "Sales"
    when "East" then "Profit"
    when "South" then "Quantity"
    when "West" then "Discount" 
  6. Create a calculation called Metric Show/Hide. Adding this calculation into our view will prevent the user from selecting multiple metrics. Note: right now it only prevents users on desktop from selecting multiple metrics but when published, users could select multiple by holding down command/control (however, it won’t break the view!)
    if [Metric] then "show" else "hide" END
  7. Create one last calculation called placeholder. This will serve as a way to create fake buttons.
  8. Add region to the rows shelf. Then to the right of region, add metric show/hide. Add placeholder to the columns shelf.
  9. Add metric label to the label mark. Right click on the placeholder axis and edit to be fixed from 0 to 1. Then right click on the axis and uncheck show header.
  10. Add the metric set to the color mark.
  11. Clean up the formatting. Click on the region and metric show/hide pill and unselect show header. Set row and column dividers to none. Make the size of the bar slightly bigger. Format the label to be left aligned and change the colors.
  12. Create a new worksheet. Add metric calc to the text mark. Update the font size to make larger.
  13. Create a new dashboard and add both worksheets
  14. Add a new set action. This can be done by going to Dashboard > Actions > Add Action > Change Set Values. Run the set on select of the select metric worksheet. Clearing the selecting will keep set values.
  15. Test it out! Clicking on the desired metric should update the worksheet!
  16. Because each metric requires different formatting, a calculation (or two) needs to be written to allow sales and profit to show as currency and discount to show as a %. Check out Ryan’s blog post for one method to do this and Decisive Data for another. I used the following for sales and profit:
    case MIN({MIN(if [Metric] then [Region] END)}) 
    when "Central" then "$" 
    when "East" then "$" 

    And the following for discount:

    case MIN({MIN(if [Metric] then [Region] END)})
    when "West" then "%"

    I then added them to my label.

To view my working example on Tableau Public or to download my workbook, click here. Also, check out the other dashboards in the workbook detailing different ways to drill down into data using set actions.