Switch Between Fields

Switch Between Measure Fields

Create a parameter and calculated field to enable a user to choose which measure (field) for the chart. There is no parameter action on this chart. Instead, when a user selects the measure name in the parameter control, a calculated field on the Columns shelf displays the selected field data. 

In this example, we’ll switch between sales and profit with a dynamic measure. If you need different types of formatting, such as percentage and currency, add formatting to the calc field in addition to the parameter logic.


Data & Fields

For this visualization, in addition to the “Category” field, I use the “Sales” or “Profit” field. 

  Category

  Sales

  Profit

Calculated Field

The calculated field logic uses a parameter, so I create the parameter first.

  Sales or Profit.calc

Columns Shelf

The  Columns shelf has the new calc field, “Sales or Profit.calc”. 

Rows Shelf

The “Category” field is on Rows shelf.

Parameter & Parameter control

This example has a parameter, “Sales or Profit.p.” Users can click the parameter control to switch between measure fields.

Sales or Profit.p

Marks Card: Color Tile

The values in my data set include negative and positive numbers for the “Profit” field, so I use a diverging color palette with 2 Steps for the Stepped Color.

Create the Viz

1. After connecting to a data source, click the drop-down arrow at the top of the Data pane to create a parameter.

2. In the bottom of the Data pane, right-click the parameter and select “Show Parameter.” The parameter control is shown on the right. When you right-click the drop-down arrow, you can edit the title and change the appearance of the control.

3. Create the calculated field (after creating the new parameter.) At the top of the Data pane, use the drop-down arrow to select “Create Calculated Field.”


4. Add the new calculated field to the Columns shelf.

5. Add the calculated field to Color on the Marks card.


6. Click the Color tile on the Marks card to open the ”Edit Colors” dialog. Check “Stepped Color” and change the “Steps” value to 2.

Testing

Click within the Parameter Control on the right to switch between measures. When “Profit” is selected the negative colors are a different color.


Switch Between Aggregation Sum & %


Using parameters to change aggregations and calc fields is similar to the previous example, “Switch Between Measures.” 


In this example, I have one calculated field that uses a case statement to return a sum or percentage calculation based on the selected parameter, “Select Aggregation.” I’ve also included formatting in the expression. 

Switch Between Dimensions

This example uses a parameter to filter dimension values along the same lines as the previous parameter examples. I am not using the Filter shelf. Instead, I created a “Yellow Fruit Group” group based on the “Fruit” field. The parameter “Pick filter field” switches between the “Fruit” dimension, which is all fruit, and the group. A calculated field “calc to pick field” on the Rows shelf switches between the two fields.

 


The calculated field selects the field or group.