CertSafari
    Snowflake SnowPro Advanced: Data Analyst (DAA-C01)· Lessons

    Domain 3 · Lesson 16/19

    Forecasting numeric time series with REGR functions and SNOWFLAKE.ML.FORECAST

    Perform forecasting.

    16 min read
    8% of exam
    7 sources
    Published 20 Oct 2026
    Docs as of 4 Oct 2026

    What you will be able to do

    • Fit a straight-line trend with REGR_SLOPE and REGR_INTERCEPT, apply it to a new x value, and judge the fit with REGR_R2
    • Train a SNOWFLAKE.ML.FORECAST model object and call its FORECAST method with the correct syntax
    • Forecast many series from one model with SERIES_COLNAME, and forecast with exogenous features by supplying future feature rows
    • Read FORECAST, LOWER_BOUND and UPPER_BOUND, and assess a model with SHOW_EVALUATION_METRICS and EXPLAIN_FEATURE_IMPORTANCE

    Key concept

    Train-then-call model object — Snowflake's ML functions are not functions you apply to a column. You first create a schema-level model object from training data with CREATE SNOWFLAKE.ML followed by the class name, such as FORECAST, then call methods on that object with the model!METHOD(...) syntax to get predictions, metrics and explanations.

    1.A linear trend in plain SQL with REGR_SLOPE, REGR_INTERCEPT and REGR_R2

    The cheapest prediction in Snowflake is a straight line. Three aggregate functions from the linear regression family fit one in a single query, with no model object and no training step. REGR_SLOPE(y, x) gives the line's slope and REGR_INTERCEPT(y, x) gives where it crosses x = 0, so the line is y = intercept + slope × x. REGR_R2(y, x) tells you how much to trust that line.

    Argument order is the first thing to get right. All three take the dependent variable (the thing you want to predict) first and the independent variable second. Write REGR_SLOPE(revenue, day_number), not the reverse. If you swap them, you get the slope of a different regression, and nothing raises an error. Both arguments must evaluate to numbers, so a trend over time needs the date turned into a numeric x first, such as a day count.

    The three regression functions, what each computes, and what you use it for
    FunctionComputed asUse it to
    REGR_SLOPE(y, x)COVAR_POP(x,y) / VAR_POP(x)Get the change in y per unit of x (the trend rate)
    REGR_INTERCEPT(y, x)AVG(y) - REGR_SLOPE(y,x) * AVG(x)Anchor the line, so you can compute intercept + slope × x for a new x
    REGR_R2(y, x)POWER(CORR(y,x), 2); NULL if VAR_POP(x) = 0Judge the fit: near 1 means the line explains y well

    Only non-null pairs count. A row where either y or x is NULL is dropped from the fit. In the example below, group 1 has one row and its x is NULL, so it has no usable pairs and returns NULL. Group 2's row (25, null) is ignored, and its other three rows give a slope of 0.831408776. On the same data, REGR_INTERCEPT(v, v2) returns 1.154734411 for group 2 and REGR_R2(v, v2) returns 0.9976905312, which means the fit is almost perfect.

    REGR_SLOPE per group: NULL pairs are skipped, and a group with no complete pair returns NULLsql
    CREATE OR REPLACE TABLE aggr(k INT, v DECIMAL(10,2), v2 DECIMAL(10, 2));
    INSERT INTO aggr VALUES(1, 10, null);
    INSERT INTO aggr VALUES(2, 10, 11), (2, 20, 22), (2, 25, null), (2, 30, 35);
    
    SELECT k, REGR_SLOPE(v, v2) FROM aggr GROUP BY k;

    These functions also run as window functions with PARTITION BY, which gives you one slope per product on every row. However, they reject an ORDER BY or an explicit frame inside OVER, so a rolling-window regression cannot be written this way.

    Checkpoint 1 of 8· Check yourself

    A daily sales table has 30 rows per product. For one product, 4 rows have a NULL revenue because those days are not reported yet, but every row has a day_number. What does SELECT product, REGR_SLOPE(revenue, day_number) ... GROUP BY product return for that product?

    Sources123

    2.Training a FORECAST model and calling it

    A straight line misses weekly cycles, holiday spikes and uncertainty. SNOWFLAKE.ML.FORECAST is a built-in machine learning function that predicts future values of a numeric time series and returns a range around each prediction. The input needs at least a timestamp column and a numeric target, ideally at a fixed interval. Training still works on real data with missing, duplicate or misaligned time steps. Your role must own the schema or hold the CREATE SNOWFLAKE.ML.FORECAST privilege on it, because the model is stored there.

    Forecasting takes two statements. The first, CREATE SNOWFLAKE.ML.FORECAST, trains a named model from a reference to your data. The second calls that model's FORECAST method. The call uses an exclamation mark between the model name and the method, and named arguments with =>, for example CALL model1!FORECAST(FORECASTING_PERIODS => 3). A dot (model.FORECAST) is not method syntax. Neither is a positional argument (FORECAST(30)). The forecast horizon is never part of CREATE: the CREATE statement takes only the data and column names, and you choose how many periods to predict each time you call.

    Training a single-series model: name the timestamp and target columns, nothing elsesql
    CREATE SNOWFLAKE.ML.FORECAST model1(
      INPUT_DATA => TABLE(v1),
      TIMESTAMP_COLNAME => 'date',
      TARGET_COLNAME => 'sales'
    );

    You don't declare the spacing between timestamps. The model infers it from the training data, so daily history gives daily forecasts. Each output row has five columns:

    Columns returned by model!FORECAST
    ColumnMeaning
    SERIESWhich series the row belongs to; NULL for a single-series model
    TSThe future timestamp being predicted
    FORECASTThe predicted value
    LOWER_BOUNDBottom of the prediction interval
    UPPER_BOUNDTop of the prediction interval

    Read the bounds alongside the forecast. LOWER_BOUND and UPPER_BOUND form the range the actual value is expected to fall in. When the history is perfectly regular, as in the documentation's toy series of 2, 3, 4…, the model makes zero errors, so both bounds equal FORECAST. Real data gives a range, and a wide range is a warning that the point forecast is soft. To change how much of the actual data the range should cover, pass prediction_interval in a configuration object, for example CALL model1!FORECAST(FORECASTING_PERIODS => 3, CONFIG_OBJECT => {'prediction_interval': 0.8});.

    To query the output or store it, call the method inside TABLE(...) in a FROM clause and drop the CALL keyword. This also lets a dashboard query pick out the FORECAST and bound columns by name.

    Saving forecasts to a table: the method goes inside TABLE(...), without CALLsql
    CREATE TABLE my_forecasts AS
      SELECT * FROM TABLE(model1!FORECAST(FORECASTING_PERIODS => 3));

    Checkpoint 2 of 8· Fill the gap

    A dashboard needs the forecast stored as a table. Which keyword completes this statement?

    CREATE TABLE my_forecasts AS
      SELECT * FROM  ? (model1!FORECAST(FORECASTING_PERIODS => 3));

    Checkpoint 3 of 8· Exam question

    An analyst owns the table DAILY_SALES(sale_date DATE, revenue NUMBER) with three years of one continuous daily series. The business wants a 30-day revenue forecast from Snowflake's built-in ML function. Which approach produces it?

    Sources4

    3.One model for many series with SERIES_COLNAME

    Without a series column, every row in the input belongs to one series. Sales from 200 stores would be treated as a single timeline with many values per date. Adding SERIES_COLNAME makes one CREATE statement train an independent forecast for each distinct value of that column. Each output row carries its series identifier in the SERIES column.

    When a series is defined by more than one column, combine them into a single column first. The documentation builds the view CREATE OR REPLACE VIEW v3 AS SELECT [store_id, item] AS store_item, date, sales FROM sales_data;, which puts store and item into an array, and then names store_item as the series column. Don't change the timestamp column or pre-aggregate with GROUP BY to get the same result. The timestamp has to stay a timestamp, and grouping merges the stores into one series instead of separating them.

    Training one forecast per store/item combination in a single statementsql
    CREATE SNOWFLAKE.ML.FORECAST model2(
      INPUT_DATA => TABLE(v3),
      SERIES_COLNAME => 'store_item',
      TIMESTAMP_COLNAME => 'date',
      TARGET_COLNAME => 'sales'
    );

    CALL model2!FORECAST(FORECASTING_PERIODS => 2); returns two rows for every series. If you only need one series, ask for it directly with CALL model2!FORECAST(SERIES_VALUE => [2,'umbrella'], FORECASTING_PERIODS => 2);. That generates only the umbrella forecast, which is cheaper than generating all of them and filtering afterwards.

    Checkpoint 4 of 8· Check yourself

    You need a separate sales forecast for every store and item pair in sales_data, which has store_id, item, date and sales columns. You want to train it all in one CREATE statement. Which setup does that?

    Checkpoint 5 of 8· Exam question

    A retailer keeps STORE_SALES(store_id, sale_date, units) for 200 stores. The analyst wants one forecasting model that trains a separate forecast for every store and returns results labelled by store. What should the CREATE statement include?

    Sources4

    4.Forecasting with exogenous features

    Features are other factors you believe move the target, such as temperature, a promotion flag or a holiday name. You don't name them anywhere. CREATE only requires the timestamp and target columns, and any other column in the training input is treated as a feature. Training on a view of date, sales, temperature, humidity and holiday therefore produces a model that uses all three extra columns.

    A feature-trained model only forecasts dates for which you supply future feature values. You pass a table or view of future rows that has the timestamp column and the same feature columns as training. You also pass TIMESTAMP_COLNAME so the method knows which column holds the dates. FORECASTING_PERIODS is left out, because the timestamps in that future table set the horizon: two rows give two forecasts, and fourteen rows give fourteen.

    Calling a feature-trained model: future feature rows replace FORECASTING_PERIODSsql
    CALL model3!FORECAST(
      INPUT_DATA => TABLE(v2_forecast),
      TIMESTAMP_COLNAME =>'date'
    );

    Checkpoint 6 of 8· Fill the gap

    model3 was trained on date, sales, temperature, humidity and holiday. The view v2_forecast holds future dates and feature values but no sales column. Which named argument completes the forecast call?

    CALL model3!FORECAST(
      INPUT_DATA => TABLE(v2_forecast),
       ?  =>'date'
    );

    Checkpoint 7 of 8· Exam question

    A model was trained on SALES_HISTORY with extra columns promo_flag and holiday_name alongside the date and the target. The analyst now needs a 14-day forecast. Select TWO requirements for calling FORECAST correctly.(Select 2)

    0 of 2 selected

    Sources4

    5.Judging a forecast model: evaluation metrics, feature importance and logs

    Every forecast model scores itself during training. By default, Snowflake also trains models on subsets of your history, predicts the rows it held back, and compares those predictions with what actually happened. model!SHOW_EVALUATION_METRICS() returns the results of that cross-validation.

    Metrics returned by SHOW_EVALUATION_METRICS
    MetricKindWhat it measures
    MAEPointMean Absolute Error
    MAPE / SMAPEPointMean Absolute Percentage Error / its symmetric form
    MSEPointMean Squared Error
    MDAPointMean Directional Accuracy
    COVERAGE_INTERVALIntervalProportion of actual values that fall inside the prediction interval
    WINKLER_ALPHAIntervalWinkler Score for the interval

    Cross-validation is controlled through CONFIG_OBJECT keys: evaluate (set it to FALSE to skip evaluation), n_splits (default 1), max_train_size, test_size and gap. Small histories can end up with no metrics at all. Evaluation needs at least (n_splits × test_size) + gap training rows, and with the default single split the STANDARD_DEVIATION column is NULL. You can also call SHOW_EVALUATION_METRICS with new data that has actual values (INPUT_DATA, TIMESTAMP_COLNAME, TARGET_COLNAME) to score the model on data it never saw.

    model!EXPLAIN_FEATURE_IMPORTANCE() ranks the features the model relied on. Each score is between 0 and 1, and the scores add up to 1. The ranking covers your own columns (FEATURE_TYPE user_provided), calendar features derived from the timestamp, and features derived from the target itself. Two near-identical features split the importance between them, so each looks less important than it is. If a model fails to fit for some series, model!SHOW_TRAINING_LOGS() reports the error for each of those series.

    Checkpoint 8 of 8· Match them up

    Match each method on a trained forecast model to the question it answers about that model.

    Tap a term, then the definition that fits it.

    Sources456

    Sources

    (7)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “Returns the slope of the linear regression line for non-null pairs in a group.”
      ↩︎ A linear trend in plain SQL with REGR_SLOPE, REGR_INTERCEPT and REGR_R2
      “When this function is called as a window function, it does not support: An ORDER BY clause within the OVER clause.”
      ↩︎ A linear trend in plain SQL with REGR_SLOPE, REGR_INTERCEPT and REGR_R2
      “Note the order of the arguments; the dependent variable is first.”
      ↩︎ Exam trap 1
    2. 2.
      “Returns the intercept of the univariate linear regression line for non-null pairs in a group.”
      ↩︎ A linear trend in plain SQL with REGR_SLOPE, REGR_INTERCEPT and REGR_R2
    3. 4.
      “Forecasting uses a machine learning algorithm that predicts future numeric data from historical time series data.”
      ↩︎ Training a FORECAST model and calling it
      “model training can handle real-world data that has missing, duplicate, or misaligned time steps.”
      ↩︎ Training a FORECAST model and calling it
      “Note that the model has inferred the interval between timestamps from the training data.”
      ↩︎ Training a FORECAST model and calling it
      “the prediction interval (LOWER_BOUND, UPPER_BOUND) is the same as the FORECAST value.”
      ↩︎ Training a FORECAST model and calling it
      “As shown in the example above, when calling the method, omit the CALL command.”
      ↩︎ Training a FORECAST model and calling it
      “To create a forecasting model for multiple series at once, use the series_colname parameter.”
      ↩︎ One model for many series with SERIES_COLNAME
      “This example uses a single time series (that is, all the rows are part of a single series)”
      ↩︎ One model for many series with SERIES_COLNAME
      “Specifying one series with the FORECAST method is more efficient than filtering the results of a multi-series forecast”
      ↩︎ One model for many series with SERIES_COLNAME
      “additional columns in the input data are assumed to be features for use in training.”
      ↩︎ Forecasting with exogenous features
      “Instead, the timestamps of the forecast come from the v2_forecast view.”
      ↩︎ Forecasting with exogenous features
      “By default, the forecasting function evaluates all models it trains using a method called cross-validation.”
      ↩︎ Judging a forecast model: evaluation metrics, feature importance and logs
      “The total number of training rows must be equal to or greater than (n_splits * test_size) + gap.”
      ↩︎ Judging a forecast model: evaluation metrics, feature importance and logs
      “These feature importance scores are then normalized to values between 0 and 1 so that their sum is 1.”
      ↩︎ Judging a forecast model: evaluation metrics, feature importance and logs
      “SELECT * FROM TABLE(my_model!FORECAST(FORECASTING_PERIODS => 7));”
      ↩︎ Exam trap 2
      “In this variation of the FORECAST method, you do not specify the number of timestamps to predict.”
      ↩︎ Exam trap 3
      “create a new column that combines these values, and specify that as the series column.”
      ↩︎ Checkpoint
      “To generate forecasts with this model, you must provide future values for the features to the model”
      ↩︎ Prediction
      “Assess your model’s accuracy. Understand the relative importance of the features the model was trained on. Debug training errors.”
      ↩︎ Checkpoint
    4. 5.
      “The <model_name>!SHOW_TRAINING_LOGS method provides error messages for any time series whose models failed to fit.”
      ↩︎ Judging a forecast model: evaluation metrics, feature importance and logs
      “You use CREATE SNOWFLAKE.ML.FORECAST to create and train the forecasting model, then use the model’s <model_name>!FORECAST method to produce forecasts.”
      ↩︎ Key concept

    Also cited

    Continue to part 2 of 2

    Predicting categories with SNOWFLAKE.ML.CLASSIFICATION

    Spotted a mistake, or was something unclear? Tell us.