This is the second in our series of worked examples for BigQuery’s AI table-valued functions. The first covered AI.KEY_DRIVERS finding why a metric moved. This one covers AI.FORECAST, which projects a time series forward without you training or choosing a model first.
BigQuery picks the forecasting approach for you based on the shape of the data you hand it. You give it a metric, a timestamp column, and how far forward to project. It works out the rest.
The dataset
We’re using the same synthetic e-commerce orders dataset as the rest of this series: nine months of daily order data, January to October 2026, with normal weekly and seasonal patterns built in. Setup instructions are in our dataset setup guide. You’ll need it loaded as bq_ai_demo.ecommerce_orders before running the query below.
The query
This forecasts daily revenue forward 30 days, broken out by product category, so you get five separate forecasts in one call rather than one blended line.
WITH daily_category_revenue AS (
SELECT
order_date,
product_category,
SUM(revenue) AS daily_revenue
FROM `bq_ai_demo.ecommerce_orders`
GROUP BY order_date, product_category
)
SELECT
product_category,
CAST(forecast_timestamp AS DATE) AS forecast_date,
forecast_value,
confidence_level,
prediction_interval_lower_bound,
prediction_interval_upper_bound,
ai_forecast_status
FROM AI.FORECAST(
(SELECT * FROM daily_category_revenue),
data_col => 'daily_revenue',
timestamp_col => 'order_date',
id_cols => ['product_category'],
horizon => 30
)
ORDER BY product_category, forecast_date;
data_col is the metric to forecast. timestamp_col is the column it uses to order the series. id_cols is the list of columns identifying separate series within the same table, in our case one series per product category. horizon is how many future periods to generate, and the function infers the period length (daily, here) from the spacing of your input timestamps.
What the result shows
Each row is one category’s forecast for one future date. forecast_value is the point forecast. prediction_interval_lower_bound and prediction_interval_upper_bound give the range either side of it, and confidence_level tells you what that range represents. ai_forecast_status reports whether the model considers that forecast reliable, which is worth checking before you present any of these numbers, especially for a category with thinner order volume.

What each column means
forecast_date: The future date this row is predicting for. We castforecast_timestampto aDATEin the query above since our input is daily; the underlying column is a timestamp becauseAI.FORECASTalso supports sub-daily and weekly/monthly series.forecast_value: The model’s single best estimate for that date. This is the number people reach for first, and the one most likely to get quoted on its own without the next three columns attached.confidence_level: The probability the function is aiming for when it builds the interval below, not a grade of how good the forecast is. We didn’t pass aconfidence_levelargument in the query above, so BigQuery uses its default (0.95, i.e. a 95% interval); pass your own value as an argument toAI.FORECASTif you want a narrower or wider range.prediction_interval_lower_bound/prediction_interval_upper_bound: The range the actual value is expected to fall within, given that confidence level. These two columns are the actual point of the function. A forecast reported without them is reported stripped of the one thing that tells you how much to trust it.ai_forecast_status: Whether the forecast for that specific date and series completed successfully, or came back with an error. It’s a pass/fail flag on the forecasting step itself, not a nuanced confidence score; if a row’s status isn’t a clean success, treat that row’s numbers as unusable rather than just less certain, and check whether that series (often a thinner-volume category) simply didn’t have enough history to forecast from.
One pattern worth watching for across the 30 days of output: the gap between the lower and upper bound should widen the further out the forecast date is from today. That’s not a flaw, it’s the function being honest that day 30 is a bigger guess than day 1, since there’s more time for the series to drift from where the model last saw it. If the interval stays the same width across the whole horizon, that’s worth a second look.
What this is actually useful for
The honest case for AI.FORECAST isn’t that it’s a better model than whatever a data team would have built anyway. It’s that it removes the setup cost. No choosing between exponential smoothing and ARIMA, no separate CREATE MODEL step, no retraining schedule to maintain. For a quick directional read, five minutes and one query is a different proposition to a modelling exercise someone has to maintain going forward.
It’s still a forecast, not a guarantee. The prediction interval is there because the point forecast alone invites more confidence than it deserves. If you’re using this for anything a decision rests on, report the interval alongside the number, not just the number.
All articles in this series
Newsletter
Occasional notes on data, tracking & AI-readiness
No spam, no growth-hacking. Just an email when there's something worth reading.