> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://help.sigmacomputing.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://help.sigmacomputing.com/_mcp/server.

# Top N filter

> Use Top N filters in Sigma to show the top number of rows by criteria. Ideal for sorted lists with many values.

It's very common to filter columns by Top N, the top number (N) of rows, based on the filter criteria. This is useful when you want to see the top values in a sorted list, instead of the whole list.

> **Info**
>
> Because of the way Sigma automatically handles aggregations and groupings, the Top N filter may behave slightly differently than what you may have experienced with other products. See the examples and tips below for details.

## Examples of Top N

### How Applying Top N Changes a Bar Chart

For example, you may be interested in the top 5 stores that move the most merchandise, sorted by state. Before applying the Top N filter, a bar chart may look like this:

![Bar chart titled Sum of Quantity by Store State, listing states from California down to Maine sorted in descending order with no Top N filter applied.](/_fern-files/_img/1d63b48806466ababdddd28c3654bfae2396be4c6f9114f11705029dc55ed81d.webp)

> **Tip**
>
> Maximize the chart to see its data table underneath. Sometimes it is helpful when applying filters to see how the filters change the table.

After applying Top N to the *Sum of Quantity* column, the chart looks like this:

![Bar chart titled Sum of Quantity by Store State with the Top N filter set to 5 on Sum of Quantity, showing only California, Texas, Florida, Arizona, and North Carolina.](/_fern-files/_img/e87489c16191692f1643578925963f5cc5683add0a1ac01dc79ccdfde4665e66.webp)

### Relationship of Top N Bar Chart to its Table

This example shows a maximized view of a chart, which includes its data table. The Top N filter is on the *Sum of Price* column. (If you put the filter on the *Store City* column, Sigma would filter the cities alphabetically.) This results in the list of 10 cities whose stores have the highest total prices of all things sold.

![A maximized bar chart titled Sum of Price by Store City with the Top N filter set to 10 on Sum of Price, showing its underlying data table with columns including Store City and Sum of Price.](/_fern-files/_img/97c4c621e8fa80911149d2be8c957f0f67240fe1e52d584a9a316a7723c20dd2.webp)

### Top N on a Pivot Table with Multiple Groupings

When there are multiple grouping levels, the Top N filter does not filter the overall top 10 items; instead it filters within a bin defined by the 2nd lowest grouping level. In this example, Top N will apply to the Top 10 *Store City* rather than the Top 10 *Store Region* or *Store State*.

![A pivot table grouped by Store Region, Store State, and Store City, with the Massachusetts group outlined to show the Top N filter applied within that state rather than across all cities.](/_fern-files/_img/4606b76319fd9d5aaeed66fa0b45ca03d8178ea4f7a1e1df5de571e7a0b6c2d8.webp)

### Additional Examples

For more in-depth examples see the Community article [How to Use a Top N Filter Parameter for Visualizations](https://community.sigmacomputing.com/t/how-to-use-a-top-n-filter-control-for-visualizations/2055).

Also see the video from phData, [Understanding Top N Filters in Sigma](https://youtu.be/eTqEodEPRZc\)).

### Related Filters: Bottom N, Top Percentile, Bottom Percentile

You can use the same process as described above to use the other filters in the same dropdown.

![The filter type dropdown open with Top N, Bottom N, Top percentile, and Bottom percentile options listed.](/_fern-files/_img/76cb9da1dc85cb9d12676f4f27c99c496d198aba04b534d93f18ee6d1974a70a.webp)

## How to Filter Using Top N

1. Set up the columns on a bar chart.

   * Select a new visualization using + ADD ELEMENT > DATA ELEMENTS > VIZ.
   * Add a column to the Y axis.
   * Add a column to the X axis. Keep the default aggregation.

     > **Info**
     >
     > Sigma requires an aggregated column when using Top N.
2. If needed, set the sort criteria.
3. For the column you want to filter, select its menu > Filter.

   ![The Store Name column menu open with the Sort and Filter options visible.](/_fern-files/_img/43103b78d5f6bc221b3862f60f107480fc7241cbe0ae711150e1d101c7eed866.webp)

   > **Info**
   >
   > Set the Top N filter on the column you want to be ranked. This can be counter-intuitive. In the example above, you want to show the top 10 Stores, so you would rank on *Store Name*, not on *Sum of Quantity*.
4. In the Filter panel, click the 3 dots to see the options.

   ![The Filters & Controls panel for the Store Name filter, with the 3-dot menu highlighted to open its options.](/_fern-files/_img/94c8b9fee55ee949e7231dae1c314a1aed9ddd6851c5cc62cc5856a1e10c9b11.webp)
5. Select Top N.

   ![The Store Name filter's Change filter type menu with the cursor selecting Top N from List, Text match, and Top N options.](/_fern-files/_img/20b7c3fa2099c1a73a93e743badd693669c5c24a2a77137cf657b9d395a2e97e.webp)
6. Enter the number of results to display.

   ![The Store Name filter set to Top N with the results count field entered as 10.](/_fern-files/_img/f24a9dfa01262d7cd299a76be0d5dd371c0d7a306dcf34553131b20b184d5796.webp)
7. Change the default chart header to best describe the filtered chart. For example, change *Sum of Quantity by Store Name*, which is an internally-produced name, to *Top 10 Stores by Quantity Sold*.

### Change the Ranking Function

By default the Top N filter uses the [Rank](/docs/rank) function. In some cases you may want to change it to the [RankDense](/docs/rankdense) or [RowNumber](/docs/rownumber) functions instead. The options are:

* **Rank**[:](/docs/rank) Assigns the same rank to duplicate values, and a gap is placed between the ranks. See [Rank](/docs/rank). Default.
* **Rank Dense**: Assigns the same rank to duplicate values, and there is no gap between ranks. See [RankDense](/docs/rankdense).
* **Row Number**: Ranks according to the highest row numbers. See [RowNumber.](/docs/rownumber)

To change the ranking function:

1. From the control's filter icon at the top right of the control, open the control's FILTERS & CONTROLS panel.
2. From the filter's **More** menu, select Ranking function.

   > **Tip**
   >
   > The text next to the menu option shows the currently-used function. By default it is Rank.
3. Select the type of rank you want.

   ![The Sum of Quantity Top N filter's More menu with Ranking function submenu open, showing Rank, Rank Dense, and Row Number options with Rank checked.](/_fern-files/_img/5c2c79e727a2afefb23ab676ae866718bd108b73d281208efacfb3b37743403c.webp)

## Tips for Top N

* Maximize the chart so you can see the table fields as you apply filters.
* Only apply the top N filter to the column that is being ranked.

  For example, you want a bar chart showing the top ten product types. You put *Product Type* on the X-axis and *Sum of Revenue* on the Y-axis, then put the Top N filter on the *Sum of Revenue* column. This gives you the top 10 values of *Sum of Revenue* grouped by *Product Type*.

  Otherwise, if you put Top N on the *Product Type* column the chart will sort the products alphabetically.
* Sigma requires an aggregated column for Top N.
* Top N applies only to columns of type text, number, or date.
* For a text column, the top N is determined by alphanumeric sorting.

## Related resources

* [Rank](/docs/rank)
* [How to Use a Top N Filter Parameter for Visualizations (Community)](https://community.sigmacomputing.com/t/how-to-use-a-top-n-filter-parameter-for-visualizations/2055)
* [Understanding Top N Filters in Sigma](https://youtu.be/eTqEodEPRZc)