> 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.

# Example representation: Workbook with a top N control

> Example Sigma code representation of a workbook with a top N control.

This is an example representation of a workbook, retrieved using the [Get a workbook](/reference/get-workbook) endpoint with the query parameter `includeContents=true`. Representations like this one can be used to create a workbook from code using the [Create a workbook](/reference/create-workbook) endpoint. Each page in this example library includes the code representation of the workbook and step-by-step instructions to create it in the Sigma UI.

Consult this example and others in the [Workbook representation example library](/docs/workbook-representation-example-library) to:

* Troubleshoot the formatting of a particular feature in code representation
* Relate a feature from the Sigma UI to its representation in code
* Provide context to AI tools used to create workbooks from code

> **Warning**
>
> This example representation cannot be used as-is. All identifying details, such as IDs, names, and URLs, have been replaced with randomized ID values or generic substitutions. The format of these contents, like the length of ID values, is preserved for demonstrative purposes. However, this representation cannot be directly used without modification to the base URL, connection details, and more. For more information, see [Create and manage workbooks from code](/docs/manage-workbooks-as-code).

## System and user requirements

To complete the steps in this example, you must meet the user requirements listed below for creating the workbook in the UI and creating it from code.

The ability to create this workbook in the Sigma UI requires the following:

* You must be assigned an [account type](/docs/account-type-and-license-overview) with the **Create, edit, and publish workbooks** permission enabled.
* You must have access to a connection to a data platform.

The ability to create a workbook from code requires the following:

* You must be assigned an [account type](/docs/account-type-and-license-overview) with the **Create, edit, and publish workbooks** permission enabled.
* You must have developer credentials for the Sigma API. For more information, see [Get started with the Sigma REST API](/reference/get-started-sigma-api).

This example uses a table from the [Sigma Sample Connection](/docs/sigmas-sample-connection). Your organization might have disabled access to the Sigma sample connection. If so, you can contact an admin to enable it, or use a table from another connection to follow along with this example.

## Create the example workbook in the Sigma UI

This example shows a workbook with a top N control that limits a bar chart to the highest-ranked stations.

To create this workbook in the Sigma UI:

1. Go to the **Home** page.

2. Select ![](https://sigma-docs-screenshots.s3.us-west-2.amazonaws.com/Icons/button-add.svg) **Create new** > **Workbook**.

   A new workbook opens.

3. From the **Add element** bar, select **Data** > **Table**.

4. In the **Select source** modal, search for the table `TRIP` in the `EXAMPLES.BIKES` schema.

5. Select the table to add it to the workbook.

   The table appears in the workbook.

6. With the table selected, select ![](https://sigma-docs-screenshots.s3.us-west-2.amazonaws.com/Icons/add-dependent.svg) **Create child element** > **Chart**.

   A new bar chart element appears on the workbook canvas.

7. In the editor panel, select **Properties** and configure the bar chart with the following settings:

   | Option     | Setting                   |
   | :--------- | :------------------------ |
   | **X-axis** | *Start Station Name*      |
   | **Y-axis** | Count of rows (`Count()`) |

8. From the **Add element** bar, select **Controls** > **Top N**.

9. Select the control, then in the **Properties** tab of the editor panel, enter `Row-Count` as the **Control ID**.

10. Select **Targets**, then add the bar chart as a target, ranking on the count of rows.

11. Set the control value to `10`.

    The bar chart now shows only the 10 stations with the most trips.

12. In the document header, select **Save as**.

13. Enter a name for the workbook, such as `top-n-control`.

14. Select **Save**.

## Get a code representation of this workbook

To get a representation of this workbook, follow the steps in [Get the code representation of a workbook](/docs/get-the-code-representation-of-a-workbook).

The code representation of this workbook appears like the following:

#### YAML representation

```yaml
workbookId: 4dad2986-ce83-4960-aa06-e9ab85a0bcc1
workbookUrlId: 9xslXTTIQrh6bpy0VAq3GZ
createdBy: uO2R8UziJdi0Y4mj4TIJZ9RnvIh4T
updatedBy: uO2R8UziJdi0Y4mj4TIJZ9RnvIh4T
createdAt: '2026-09-01T14:53:44.615Z'
updatedAt: '2026-11-03T20:03:26.798Z'
name: top-n-control
url: https://aws-api.sigmacomputing.com/org-name/workbook/9xslXTTIQrh6bpy0VAq3GZ
path: My Documents/<folder-name>
latestVersion: 3
ownerId: uO2R8UziJdi0Y4mj4TIJZ9RnvIh4T
isArchived: false
contents:
  schemaVersion: 1
  elements:
    - id: OetAfG8
      kind: table
      source:
        connectionId: ff0f3b81-a3e2-489c-b95e-846bdbd5f6d2
        kind: warehouse-table
        path:
          - EXAMPLES
          - BIKES
          - TRIP
      columns:
        - id: MjRZA0G6v
          formula: '[TRIP/Id]'
        - id: bBxKd5WVwd9
          formula: '[TRIP/Duration]'
        - id: ExLXa3zphJn9
          formula: '[TRIP/Start Date]'
        - id: pH9xdreYrmVM
          formula: '[TRIP/Start Station Name]'
        - id: 1JIJ5iqQt6
          formula: '[TRIP/Start Station Id]'
        - id: wukvg6KLYr
          formula: '[TRIP/End Date]'
        - id: vadWwbDVrE
          formula: '[TRIP/End Station Name]'
        - id: OdUmtqeV
          formula: '[TRIP/End Station Id]'
        - id: T6FbNKHRi
          formula: '[TRIP/Bike Id]'
        - id: zFU89L0zlm
          formula: '[TRIP/Subscription Type]'
        - id: q9jRh6
          formula: '[TRIP/Zip Code]'
      order:
        - MjRZA0G6v
        - bBxKd5WVwd9
        - ExLXa3zphJn9
        - pH9xdreYrmVM
        - 1JIJ5iqQt6
        - wukvg6KLYr
        - vadWwbDVrE
        - OdUmtqeV
        - T6FbNKHRi
        - zFU89L0zlm
        - q9jRh6
    - kind: control
      controlId: Row-Count
      id: nd1ItZ46uZudk
      filters:
        - source:
            kind: table
            elementId: 7AfSX
          columnId: t1qQzEeI
      controlType: top-n
      rankingFunction: rank
      mode: top-n
      rowCount: 10
      includeNulls: when-no-value-is-selected
    - id: 7AfSX
      kind: bar-chart
      source:
        elementId: OetAfG8
        kind: table
      columns:
        - id: ch_pH9xdreYrmVM
          formula: '[TRIP/Start Station Name]'
        - id: t1qQzEeI
          formula: Count()
      yAxis:
        columnIds:
          - t1qQzEeI
      xAxis:
        columnId: ch_pH9xdreYrmVM
  pages:
    - id: FLz0FoJA
      name: Page 1
  kind: workbook
  layout: |
    <?xml version="1.0" encoding="utf-8"?>
    <Page type="grid" gridTemplateColumns="repeat(24, 1fr)" gridTemplateRows="auto" id="FLz0FoJA">
      <Element elementId="OetAfG8" gridColumn="1 / 25" gridRow="1 / 14"/>
      <Element elementId="nd1ItZ46uZudk" gridColumn="1 / 9" gridRow="14 / 17"/>
      <Element elementId="7AfSX" gridColumn="1 / 25" gridRow="17 / 31"/>
    </Page>
documentVersion: 3

```

## Representing top N controls

#### Top N control representation

```yaml
...
kind: control
controlId: Row-Count
id: nd1ItZ46uZudk
filters:
- source:
    kind: table
    elementId: 7AfSX
  columnId: t1qQzEeI
controlType: top-n
rankingFunction: rank
mode: top-n
rowCount: 10
includeNulls: when-no-value-is-selected
...
```

## Related resources

* [Manage workbooks as code](/docs/manage-workbooks-as-code)
* [Top N filter](/docs/top-n-filter)