Top/Bottom N Parameter Use Case

This topic describes how to use a parameter as a free form text input filter control. In this use case, the user enters a value that interacts with and controls the visualization's top N value.

Use Case Description

A Top Bottom N filter's value is set when the visualization is created. You can now use a parameters as a free form text input filter control where the user can select a Top N value to change the data that is displayed in the visualization.

This use case uses the Sample Order Line dataset.

The steps for this use case are:

Create the Visualization

To start this use case, create or open a workbook and add a horizontal bar chart that has Cities on the X-axis and Sale on the Y axis.


Horizontal bar chart

Create the Parameter

Go to the workbook's Parameters tab to create the parameters required for this use case.

Parameter Tab
  1. In Name, enter Top N.
  2. In Data Type, select Integer.
  3. In Allow Multiple Values, leave it set to Off because the parameter will be used as a single-entry filter.
  4. In Alias, leave it set to Off.
  5. In Possible Value Type field, select Any.
  6. In Initial Value, select Value and enter 10.
  7. Click OK to save the parameter.

Top N parameter properties

Create the Expression Filter

In the expression, the Rank function calculates a rank for each row within a result set, and the operator <= limits the value returned by the parameter Top N, which uses a default value of 10.

  1. Confirm that the visualization's Grammar panel is displayed.
  2. Scroll to the Filters area, click Drop Target Options, and select Add Expression Filter.
  3. In Label, enter Top N.
  4. In the Expression field, compose this expression:
    rank(Sales)<=@parameter("Top N")(10)
  5. Click Validate, and then click Save to save the calculation.
  6. In the filter bar, right-click the Top N filter and clear Show Filter to hide the filter.

TopN expression

Add the Parameter as a Filter Control on the Canvas

  1. Click the workbook's Visualization tab and scroll to the Dashboard Controls section.
  2. Drag and drop the Dashboard Filters control to the canvas.
  3. Click the workbook's Parameters tab.
  4. Drag and drop the Top N to the grammar panel's Filter Controls area.
  5. Click Save to save the workbook.

Top N parameter as filter control