To aggregate time-based dimensions, use the time_grain or time_grains parameters instead of using date functions (like .month()) in filters.
Global Time Grain
Use time_grain to apply the same grain to all time dimensions in the query.
Requirement: You MUST include the time dimension in the dimensions list.
Available Grains (short or long form):
year / TIME_GRAIN_YEARquarter / TIME_GRAIN_QUARTERmonth / TIME_GRAIN_MONTHweek / TIME_GRAIN_WEEKday / TIME_GRAIN_DAYhour / TIME_GRAIN_HOURminute / TIME_GRAIN_MINUTEsecond / TIME_GRAIN_SECOND
Per-Dimension Time Grains
Use the time_grains dictionary when different dimensions require different aggregation levels.
Time Range Filtering
Use the time_range parameter for preferred time-based filtering. It handles ISO 8601 formats and time zones automatically:
{
"start": "2024-01-01T00:00:00Z",
"end": "2024-12-31T23:59:59Z"
}
query_model(
model_name="orders",
dimensions=["orders.order_date", "orders.ship_date"],
measures=["orders.total_sales"],
time_grains={"orders.order_date": "month", "orders.ship_date": "quarter"}
)