> ## Documentation Index
> Fetch the complete documentation index at: https://docs.elementary-data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# time_bucket

<Card title="Generate your anomaly test with Elementary AI" icon="wand-magic-sparkles" horizontal="true" href="https://elementary-data.com/community">
  Let our Slack chatbot create the anomaly test you need.
</Card>

```
time_bucket:
  period: < time period > # supported periods: hour, day, week, month
  count: < number of periods >
```

This configuration controls the duration of the time buckets.

To calculate how data changes over time and detect issues, we split the data into consistent time buckets.
For example, if we use daily (period=`day`, count=`1`) time bucket and monitor for row count anomalies, we will count new rows per day.

Depending on the nature of your data, it may make sense to modify this parameter.
For example, if you want to detect volume anomalies in an hourly resolution, you should set the time bucket to period=`hour` and count=`1`.

* *Default: daily buckets. `time_bucket: {period: day, count: 1}`*
* *Relevant tests: Anomaly detection tests with `timestamp_column`*

<Frame caption="time_bucket change impact">
  <img src="https://res.cloudinary.com/diuctyblm/image/upload/v1681301377/Anomaly%20detection%20tests/time_bucket_ypxuxu.png" alt="time_bucket change impact" />
</Frame>

<RequestExample>
  ```yml test theme={null}
  models:
    - name: this_is_a_model
      data_tests:
        - elementary.volume_anomalies:
            arguments:
              time_bucket:
                period: day
                count: 2
  ```

  ```yml model theme={null}
  models:
    - name: this_is_a_model
      config:
        elementary:
          time_bucket:
            period: hour
            count: 4
  ```

  ```yml dbt_project.yml theme={null}
  vars:
    time_bucket:
      period: hour
      count: 12
  ```
</RequestExample>

#### How it works?

* The `training_period` and `detection_period` of the test might be extended to ensure full time buckets (for example, full week Sunday-Saturday).
* Weekly buckets start at the day that is configured as week start on the data warehouse.
