Stay organized with collectionsSave and categorize content based on your preferences.
The AI.FORECAST function
This document describes theAI.FORECASTfunction, which lets you
forecast a time series by using BigQuery ML's built-inTimesFM model.
Using theAI.FORECASTfunction with the built-in TimesFM model lets you
perform forecasting without having to create and train your own model, so you
can avoid the need for model management.
TABLE_NAME: the name of the table that contains the
data that you want to forecast. For example,`mydataset.mytable`.
If the table is in a different project, then you must prepend the
project ID to the table name in the following format, including backticks:
`[PROJECT_ID].[DATASET].[TABLE]`
For example,`myproject.mydataset.mytable`.
To prevent query errors, we recommend providing the fully qualified table
name, including backticks. This is especially important if the project name
contains characters other than letters, numbers, and underscores.
QUERY_STATEMENT: the GoogleSQL query that
generates the data that you want to forecast. See theGoogleSQL query syntaxpage for the supported SQL syntax of thequery_statementclause.
DATA_COL: aSTRINGvalue that specifies the name of
the data column. The data column contains the data to forecast. The data
column must use one of the following data types:
INT64
NUMERIC
FLOAT64
TIMESTAMP_COL: aSTRINGvalue that specified the
name of the time points column. The time points column provides the time
points used to generate the forecast. The time points column must use one of
the following data types:
TIMESTAMP
DATE
DATETIME
MODEL_NAME: aSTRINGvalue that specifies the name
of the model.TimesFM 2.0is the only supported value, and is the default
value.
ID_COLS: anARRAY<STRING>value that specifies the
names of one or more ID columns. Each ID identifies a unique time series to
forecast. Specify one or more values for this argument in order to forecast
multiple time series using a single query. The columns that you specify must
use one of the following data types:
STRING
INT64
ARRAY<STRING>
ARRAY<INT64>
HORIZON: anINT64value that specifies the number of
time points to forecast. The default value is10. The valid input range is[1, 10,000].
CONFIDENCE_LEVEL: aFLOAT64value that specifies the
percentage of the future values that fall in the prediction interval. The
default value is0.95. The valid input range is[0, 1).
Output
AI.FORECASTreturns the following columns:
id_cols: one or more values that contain
the identifiers of a time series.id_colscan be anINT64,STRING,ARRAY<INT64>orARRAY<STRING>value. The column names and types are inherited from theid_colsoption as specified in theAI.FORECASTstatement.
forecast_timestamp: aTIMESTAMPvalue that contains the timestamps
of the time series.
forecast_value: aFLOAT64value that contains the average of theprediction_interval_lower_boundandprediction_interval_upper_boundvalues.
confidence_level: aFLOAT64value that contains theconfidence_levelvalue that you specified in the function input, or0.95if you didn't specify aconfidence_levelvalue. This value is the same
across all rows.
prediction_interval_lower_bound: aFLOAT64value that contains the
lower bound of the prediction interval for each forecasted point.
prediction_interval_upper_bound: aFLOAT64value that contains the
upper bound of the prediction interval for each forecasted point.
ai_forecast_status: aSTRINGvalue that contains the forecast status.
This value is empty if the operation was successful. If the operation
wasn't successful, the value is the error string. A common error isThe time series length is less than 3, which is the minimum required length to produce a forecast.This error indicates that there wasn't enough historical data in the time
series to generate a forecast.
Example
The following example forecasts units sold by sales date for each city and store
number. The query forecasts 50 time points with a confidence level of0.75:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-03 UTC."],[],[],null,["# The AI.FORECAST function\n========================\n\n|\n| **Preview**\n|\n|\n| This product or feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA products and features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n| **Note:** To give feedback or request support for this feature, contact [bqml-feedback@google.com](mailto:bqml-feedback@google.com).\n\nThis document describes the `AI.FORECAST` function, which lets you\nforecast a time series by using BigQuery ML's built-in\n[TimesFM model](/bigquery/docs/timesfm-model).\n\nUsing the `AI.FORECAST` function with the built-in TimesFM model lets you\nperform forecasting without having to create and train your own model, so you\ncan avoid the need for model management.\n\nSyntax\n------\n\n```sql\nSELECT\n *\nFROM\n AI.FORECAST(\n { TABLE TABLE_NAME | (QUERY_STATEMENT) },\n data_col =\u003e DATA_COL,\n timestamp_col =\u003e TIMESTAMP_COL\n [, model =\u003e MODEL_NAME]\n [, id_cols =\u003e ID_COLS]\n [, horizon =\u003e HORIZON]\n [, confidence_level =\u003e CONFIDENCE_LEVEL]\n )\n```\n\n### Arguments\n\n`AI.FORECAST` takes the following arguments:\n\n- \u003cvar translate=\"no\"\u003eTABLE_NAME\u003c/var\u003e: the name of the table that contains the\n data that you want to forecast. For example, ```mydataset.mytable```.\n\n If the table is in a different project, then you must prepend the\n project ID to the table name in the following format, including backticks:\n\n ```[PROJECT_ID].[DATASET].[TABLE]```\n\n For example, ```myproject.mydataset.mytable```.\n- \u003cvar translate=\"no\"\u003eQUERY_STATEMENT\u003c/var\u003e: the GoogleSQL query that\n generates the data that you want to forecast. See the\n [GoogleSQL query syntax](/bigquery/docs/reference/standard-sql/query-syntax#sql_syntax)\n page for the supported SQL syntax of the `query_statement` clause.\n\n- \u003cvar translate=\"no\"\u003eDATA_COL\u003c/var\u003e: a`STRING` value that specifies the name of\n the data column. The data column contains the data to forecast. The data\n column must use one of the following data types:\n\n - `INT64`\n - `NUMERIC`\n - `FLOAT64`\n- \u003cvar translate=\"no\"\u003eTIMESTAMP_COL\u003c/var\u003e: a `STRING` value that specified the\n name of the time points column. The time points column provides the time\n points used to generate the forecast. The time points column must use one of\n the following data types:\n\n - `TIMESTAMP`\n - `DATE`\n - `DATETIME`\n- \u003cvar translate=\"no\"\u003eMODEL_NAME\u003c/var\u003e: a `STRING` value that specifies the name\n of the model. `TimesFM 2.0` is the only supported value, and is the default\n value.\n\n- \u003cvar translate=\"no\"\u003eID_COLS\u003c/var\u003e: an `ARRAY\u003cSTRING\u003e` value that specifies the\n names of one or more ID columns. Each ID identifies a unique time series to\n forecast. Specify one or more values for this argument in order to forecast\n multiple time series using a single query. The columns that you specify must\n use one of the following data types:\n\n - `STRING`\n - `INT64`\n - `ARRAY\u003cSTRING\u003e`\n - `ARRAY\u003cINT64\u003e`\n- \u003cvar translate=\"no\"\u003eHORIZON\u003c/var\u003e: an `INT64` value that specifies the number of\n time points to forecast. The default value is `10`. The valid input range is\n `[1, 10,000]`.\n\n- \u003cvar translate=\"no\"\u003eCONFIDENCE_LEVEL\u003c/var\u003e: a `FLOAT64` value that specifies the\n percentage of the future values that fall in the prediction interval. The\n default value is `0.95`. The valid input range is `[0, 1)`.\n\nOutput\n------\n\n`AI.FORECAST` returns the following columns:\n\n- `id_cols`: one or more values that contain the identifiers of a time series. `id_cols` can be an `INT64`, `STRING`, `ARRAY\u003cINT64\u003e` or `ARRAY\u003cSTRING\u003e` value. The column names and types are inherited from the `id_cols` option as specified in the `AI.FORECAST` statement.\n- `forecast_timestamp`: a `TIMESTAMP` value that contains the timestamps of the time series.\n- `forecast_value`: a `FLOAT64` value that contains the average of the `prediction_interval_lower_bound` and `prediction_interval_upper_bound` values.\n- `confidence_level`: a `FLOAT64` value that contains the `confidence_level` value that you specified in the function input, or `0.95` if you didn't specify a `confidence_level` value. This value is the same across all rows.\n- `prediction_interval_lower_bound`: a `FLOAT64` value that contains the lower bound of the prediction interval for each forecasted point.\n- `prediction_interval_upper_bound`: a `FLOAT64` value that contains the upper bound of the prediction interval for each forecasted point.\n- `ai_forecast_status`: a `STRING` value that contains the forecast status. This value is empty if the operation was successful. If the operation wasn't successful, the value is the error string. A common error is `The time series length is less than 3, which is the minimum required length to produce a forecast.` This error indicates that there wasn't enough historical data in the time series to generate a forecast.\n\nExample\n-------\n\nThe following example forecasts units sold by sales date for each city and store\nnumber. The query forecasts 50 time points with a confidence level of `0.75`: \n\n```sql\nSELECT\n *\nFROM\n AI.FORECAST(\n TABLE `mydataset.sales`,\n data_col =\u003e 'units_sold',\n timestamp_col =\u003e 'sales_date',\n model =\u003e 'TimesFM 2.0',\n id_cols =\u003e ['store_number', 'city'],\n horizon =\u003e 50,\n confidence_level =\u003e .75\n );\n```\n\nLocations\n---------\n\nThe TimesFM model is available in all BigQuery supported regions.\n\nLimitations\n-----------\n\nOnly the most recent 512 timepoints are used when generating the forecast.\n\nWhat's next\n-----------\n\n- Try [using a TimesFM model with the `AI.FORECAST` function](/bigquery/docs/timesfm-time-series-forecasting-tutorial).\n- For information about forecasting in BigQuery ML, see [Forecasting overview](/bigquery/docs/forecasting-overview).\n- For information about the supported SQL statements and functions for each model type, see [End-to-end user journey for each model](/bigquery/docs/e2e-journey)."]]