# Time grains (/docs/python/datasets/time-grains)

When a dataset has a `time_key`, pass a grain as `by` to bucket results by time period:

<CodeBlock>
```python
analytics.execute(
    orders,
    DatasetQuery(by="month", dimensions=("country",), measures=("revenue",)),
)
```
</CodeBlock>

Results include a `period` column, ordered ascending. Buckets are computed in the
query's time zone: `DatasetQuery(timezone="America/New_York")`, or the client's
default from `create_dataset_client(timezone=...)`, which is `UTC` unless set.

Supported grains:

- `minute`
- `hour`
- `day`
- `week` (weeks start on Sunday)
- `month`
- `quarter`
- `year`

For rolling, to-date, cumulative and period-over-period values on top of a grain, see
[window measures](/docs/python/datasets/measures#window-measures) and
[period comparisons](/docs/python/datasets/measures#period-comparisons).