Dynamically displaying and sorting measures

In this recipe, we will walk through the strategy to display and sort measures based on user selection.

Dynamically displaying and sorting measures

Getting ready

To follow this recipe, open B05527_03 – STARTER.twbx. Use the worksheet called Dynamic Measure Display and Sort, and connect to the MasterTable (FlooddataMastListrev) data source.

Getting ready

How to do it…

The following are the steps to create a chart that enables displaying and sorting measures through a parameter:

  1. Right-click the arrow beside the Dimensions section in the side bar, and select Create Parameter.
  2. Create a string parameter called Sort by with the following settings:
    How to do it…
  3. Show the parameter control for Sort by. You can do this by right-clicking on the parameter, and selecting Show Parameter Control.
  4. Create another parameter called Sort direction with the following settings:
    How to do it…
  5. Show the Sort direction parameter control.
  6. Create a calculated field called Chosen Sort by with the following formula:
    How to do it…
  7. Create another calculated field called Chosen Sort by with direction, which takes into account the selected direction.
    How to do it…
  8. From Measures, drag the calculated field Chosen sort by to the Columns shelf.
  9. From Dimensions, drag Country to the Rows shelf.
  10. Right-click on the Country pill in the Rows shelf, and select Sort.
  11. Sort the Country based on the calculated field Chosen sort by with direction in Ascending order.
    How to do it…
  12. Click OK when done.
  13. From Measures, drag Chosen sort by to the Filters shelf.
  14. Choose Special, and select Non-null values.
    How to do it…
  15. From Dimensions, drag Country to the Filters card.
  16. Under the General tab, check the Exclude option, and select Null. Notice that selecting something when the Exclude option is checked adds a strikethrough to the selected item, meaning that item will be excluded.
    How to do it…
  17. Click OK when done.
  18. Test the parameters. Ensure that as you change the parameter selection, the measures and the sorting change accordingly.

How it works…

In this recipe, we put the end users in the driver's seat and let them change the measures being displayed as they require, as well as how the measures are sorted.

Normally we place the measures we want to display in the shelves or cards. However, to allow end users to change this on demand, we must first enable them to specify their choice through a parameter. In our recipe, we called this parameter Sort by. This parameter is used in a calculated field that determines the actual measure to be used in the visualization, as well as the appropriate aggregation function:

How it works…

In addition to this, we also created another parameter called Sort direction. The Sort direction parameter is used in a calculated field called Chosen Sort by with direction that either keeps the value of the calculated field Chosen Sort by as is if ascending, or reverses it by multiplying it by -1 if descending.

How it works…

This calculated field is to be used with the sort direction for the Country dimension.

When the parameter choices change, the respective calculated fields will trigger the change in the chart, and show the appropriate measure and sort direction.

There's more…

One trick when working with dynamic measures is adding the parameter in the same shelf as the dynamic measure.

There's more…

This allows for the actual measure name to be displayed as a header in the view.

There's more…

See also

  • Please refer to the recipe in this chapter Dynamically displaying dimensions
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.176.228