Hover to Choose Field for Sorting

Hover to Choose Field for Sorting

When I first saw this example, I was intrigued. After trying the sorting, I was surprised at how insightful it was to see the price of the most expensive fruit and then look at the sales and quantity sold for that same fruit.

Introduction

In this example, there are three bar charts in one worksheet, and I want to sort a particular bar chart when someone hovers over the field name above that chart. 

Project Files

Tableau Public file


Preview - the Finished Dashboard

In this example, the finished dashboard is sorted by Qty because I hovered the mouse of Qty at the top of the dashboard.


Worksheets

There are two worksheets in this example. 

Bar Chart

The “Bar Chart” has three measure fields on the columns shelf., which creates three charts in the view.

Sales

Price

Qty

Text

The second worksheet “Text” has “Measure Values” on the Detail tile on the Marks card, and Tableau added the “Measured Values” card to the view. When I add the “Measure Names” field to the Columns shelf, Tableau also adds “Measured Names” is also added to the Filters shelf.

Data & Fields

This dashboard utilizes these fields.

  Sales

  Price

  Qty

  Fruit

  Measured Names

  Measured Values

Calc Field for Sorting 

A Placeholder field for sorting

Sales

The data type for “Sales” is a “Number (decimal).” In the “Bar Chart” worksheet “Sales” is a continuous field on the Columns shelf. This continuous field creates an axis on the view, and because the field is on the Columns shelf this is a horizontal x-axis.

Price

In the “Bar Chart” worksheet “Price” is on the Columns shelf. This is a continuous field so it creates a second chart with an axis.

Qty

In the “Bar Chart” worksheet “Sales” is also on the Columns shelf. This is a continuous field so it creates a third chart with an axis.

Fruit

The “Fruit” field is a discrete dimension with a “String”  data type. As expected, the field has a blue background  or “pill,”  because it is a discrete field. Since “Fruit” is on the Rows shelf it creates header rows on the left side of the view.

Measured Names

The three field names are discrete values in the “Measured Names” field. This field is automatically created by Tableau. In this “Text” worksheet,  I’m using “Measured Names” in three places.

• Columns shelf

• Filters shelf

• Marks card: Text

Calculated Fields

There are two calculated fields.

• Calc Field for Sorting 

• A Placeholder field

Calc Field for Sorting

This calculated field uses a case statement to choose which field is sorted. The “Fruit” field is sorted using the “Calc Field for Sorting” on the “Bar Chart” worksheet.

Placeholder

There is an empty string field on the “text” worksheet. This “Placeholder” field is simply used for aligning the “Text” worksheet on the dashboard. A placeholder field is a simple calculation with no fieldname, in this case a blank string.

“ ”

Components or Elements

There are several elements in this workbook on the two worksheets.

• Columns Shelf

• Rows Shelf

• Measure Values Shelf

• Filters Shelf

• Parameter

• Parameter Control

• Change Parameter Action

Columns Shelf

Let’s look at the Columns shelf for each worksheet.

Bar Chart Worksheet

The “Bar Chart” worksheet has three fields on the Columns shelf, creating three charts. The aggregation for all three fields is SUM().

SUM(Sales), SUM(Price), SUM(Qty)

The “Fruit” dimension field is on “Bar Chart” worksheet Rows shelf. With a discrete setting the field creates header rows on the left side of the view. This dimension field is also sorted by the field “Calc field for sorting.”



Rows Shelf

There are two fields on the Rows shelf for the respective worksheets.

Text Worksheet

The “text” worksheet only has the field “Measure Names” on the Columns shelf. I sorted “Measured Names” in ascending order in this example. 

As shown earlier, the “Text” worksheet has a “Placeholder” dimension field with the expression for a blank string.

“ ”

Measure Values Card

Because “Measure Names” is on the Columns shelf of the “Text” worksheet, and I also added “Measure Values” to “Detail” on the Marks card, the corresponding Measure Values card is added with the three fields. In this case the aggregation is SUM(). 

• SUM(Sales)

• SUM(Price)

• SUM(Qty)


Filters Shelf

The Filters shelf has the “Measure Names” field on the “Text” worksheet. The Filters shelf is not used on the “Bar Chart” worksheet.

The “Text” worksheet also has the field “Measure Names” on the Filters shelf. This filter allows you to choose which fields are on the “Measure Values” card.


Marks: Text

For the “Text” worksheet, the field “Measure Names” is on the “Text” tile of the Marks card.

Parameter

The parameter called “Choose Field to Sort (Parameter)” uses a “Change Parameter” dashboard action with a calculated field called “Calc field for sorting.”

Change Parameter - Dashboard Action

The “Change Parameter Action” links the calculated field “Calc field for sorting” with the parameter “Choose Field to Sort (Parameter).” 

Parameter Control

By showing the “Parameter Control” for the parameter “Choose Field to Sort (Parameter)” you allow users to interactively choose a different parameter value and change the filtering. I used a very descriptive name here, but you could use anything that makes sense to you.


Create the Viz

1. Connect to the data source. Create a “Bar Chart” worksheet with three measures on the Columns shelf: Sales, Price, and Qty. Add “Fruit” to the Rows shelf.

2. Create a parameter.

3. Display the parameter control. In the bottom left corner fo the Data pane, click on the parameter drop-down menu and choose “Show parameter.”


4. On the Dashboard menu select “Actions” to open the Actions dialog box. In the bottom left corner, click on the “Add Action” button and select “Change Paramater.”

5. Create a calculated field

6. On the Rows shelf, click the “Fruit” field drop-down arrow and choose “Sort” from the context menu. For “Sort by” select “Field” and the new calculated field “Calc field for sorting,” as shown below.

7. Create another worksheet called “Text” for the three text values based on the “Measure Names” field. Add “Measure Names” to the Columns shelf, Filters shelf, and the Text tile on the Marks card. 

8. Add “Measure Values” to Detail on the Marks card. This adds the three field names to the view. You only want three fields on the Measured Values shelf, as shown below. 

• Sales

• Price

• Qty

9. Create a dashboard and add the two worksheets. The “Text” worksheet is at the top of the dashboard and the “Bar Chart” worksheet is below.

10. Create a dashboard parameter action called “Update Sort Parameter.”


Name: Update Sort Parameter

Source Sheets: Text

Run action on: Hover

Target Parameter: Choose Field to Sort (Parameter)

Clearing the select will: Keep current value

Source Field: Measured Names

Aggregation: None