---
title: "Time grouping parameter"
description: "Add a parameter to a SQL question that lets people switch between grouping results by day, week, month, and more."
url: "https://www.metabase.com/docs/latest/questions/native-editor/time-grouping-parameters"
version: "65"
---

# Time grouping parameter

You can add a parameter to SQL questions to change how results are grouped by time: by day, week, month, and so on.

To add a time grouping parameter, you'll need:

- An aggregation (like `COUNT`).
- A parameter in the `SELECT` clause
- That same parameter in the `GROUP BY` clause.

## Time grouping parameter example

Here's an example that counts the number of orders in the `orders` table and inserts a parameter to allow people to change how Metabase groups the results by the `created_at` column.

```sql

SELECT
  COUNT(*) AS "Orders",
  {{created_at_param}} AS "Created At"
FROM
  orders
GROUP BY
  {{created_at_param}}

```

Like in all SQL groupings, you must include the parameter in both the `SELECT` and `GROUP BY` clauses. You can also group by multiple columns, like so:

```sql

SELECT
  COUNT(*) AS "Count",
  {{created_at_param}} AS "Created at",
  {{trial_ends_at}} AS "Trial ends at"
FROM
  accounts
GROUP BY
  {{created_at_param}},
  {{trial_ends_at}}

```

Like with all parameters, you can set a default value (e.g., "month"). With time grouping parameters, you're limited to the options for the [time grouping parameter](https://www.metabase.com/docs/latest/dashboards/filters.md#time-grouping-parameter).

If people don't set a value for the parameter, Metabase won't group to a date part (like day or week). It will just group by untruncated dates.

## Handling aliases

Just like with field filters, if you alias a table, then map a time grouping parameter to a field in that aliased table, you'll need to [tell Metabase about the table and field alias](https://www.metabase.com/docs/latest/questions/native-editor/field-filters.md#specifying-the-table-and-field-alias).

## Connecting to a dashboard filter

See [dashboard filters and parameters](https://www.metabase.com/docs/latest/dashboards/filters.md).
