A Filter “Condition” Formula with Two Parameters, s1065

Closed Captioning

Top N and Range Filtering with Parameters

Hi! Today I want to demonstrate how to create a Top N filter and use two parameters to create a custom range filter.

Step 1: Building the Initial View

To start, I'll drag the Measure Names field from the Data pane and place it on the Columns shelf. Next, I’ll put the City field on the Rows shelf. Finally, I’ll drag Measure Values from the bottom of the Data pane and drop it onto Text.

You’ll notice that Tableau automatically created a Measure Values shelf and added all available measure fields into the view as columns. I don’t want all of these fields, so I’m going to drag Count of Orders, Discount, Profit, and Quantity off the shelf.

Tip: You can also control which measures appear by right-clicking the Measure Names filter and selecting or deselecting the fields from the list.

Step 2: Creating the Parameters

Now, I’d like to create two parameters that my users can use to define a sales range. At the top of the Data pane, I’ll click the drop-down arrow and select Create Parameter:

  1. Bottom Sales Value: I'll set the data type to Float.

  2. Top Sales Value: I'll create a second parameter with the same settings.

The new parameters appear at the bottom of the Data pane. I’ll click the drop-down arrow on each and select Show Parameter. This displays the controls on the right, allowing users to enter their own start and end values.

Step 3: Applying the Condition Filter

I want to create a filter on City that uses a specific formula to look at our new parameters. I'll drag City to the Filters shelf and go to the Condition tab. I’ll select By formula and enter: SUM([Sales]) < [Top Sales Value] AND SUM([Sales]) > [Bottom Sales Value]

Note: In the calculation window, parameters appear in purple and fields appear in orange.

Step 4: Adding the Top N Limit

Currently, I have no rows because I haven't set a value yet. I'll enter 10,000 as the Top Sales Value. Now I see many cities, but I want to limit this to just the top performers within that range.

  1. Right-click the City filter and select Edit Filter.

  2. Click on the Top tab.

  3. Select By field, set it to Top 10, and choose Sales (Sum).

  4. Click OK.

Testing the Result

Now the view shows the top 10 cities that fall within my specified sales range. If I change the Bottom Sales Value to 6,000 and the Top Sales Value to 20,000, the list updates to show only the top 10 performers whose sales are between those two figures.