What you will be able to do
- Describe the parts of a time-series record that let you trace a pattern back to a cause
- Collect related data for a diagnosis, including a table's past state via Time Travel and outside factors as extra variables
- Downsample fine-grained data with TIME_SLICE and DATE_TRUNC to show trends and to line up datasets recorded at different granularities
- Measure the relationship between two metrics with CORR and explain why its NULL handling matters
Key concept
Dimensions as the route to a cause — Diagnostic analysis asks why a metric moved, and the answer is almost always in the attributes stored next to the measurement, such as location, device, customer or product. If you don't collect those dimensions and line them up with the metric, the most you can say is that something changed, not why.
1.What you are diagnosing: anomalies and patterns in historical data
Descriptive analysis reports what happened. Diagnostic analysis explains why it happened. Most diagnostic work in Snowflake starts from historical time-series data, meaning sequential observations that record how a system, process or behaviour changed over time. Snowflake's documentation breaks a single time-series record into three parts: a date, time or timestamp at a consistent granularity; one or more measurements, usually numeric; and the dimensions linked to each measurement, such as the location of a temperature reading or the stock symbol of a trade.
Each part does a different job. The measurement holds the signal, which the documentation describes as facts that might reveal trends or anomalies in the data. The timestamp tells you when the signal changed. The dimensions tell you where to look for the cause. The documentation's own example is a run of temperature readings taken every 15 seconds. They sat around 35°C for a day and then peaked above 40°C. Seeing the peak is the descriptive step. Asking which device, which line and what else changed at that moment is the diagnostic step.
| Part | Example from the docs | Diagnostic role |
|---|---|---|
| Timestamp | DEVICE_TIMESTAMP 2023-01-01 00:01:00.000 | Shows when the pattern started |
| Measurement | TEMP 21.1673, PRECIP 0.32 | Holds the anomaly or trend itself |
| Dimension | CITY, STATE, DEVICE, LINE | Narrows down where the cause sits |
Checkpoint 1 of 6· Check yourself
A temperature series shows a sudden spike. Which part of the time-series record lets you attribute the spike to one factory line rather than another?
Dimensions such as device, line or location are stored with each measurement, and they are what let you split a metric and trace a change to a particular source. The timestamp only says when it happened.
“Dimensions of interest that are associated with the measurement”Source: docs.snowflake.com
Sources1
2.Collecting the related data a diagnosis needs
A diagnosis is only as good as the data in front of you. Three kinds of related data come up again and again: the earlier state of the same table, outside factors that may have pushed the metric, and a curated input set built for the question you are asking.
The earlier state of the same table. If a total changed and you suspect a job modified the data, you need to compare the table now with the table as it was before. Time Travel provides this. You add an AT or BEFORE clause in the FROM clause, straight after the table name, and choose a point in the past by TIMESTAMP, OFFSET, STATEMENT or STREAM. With AT, the request is inclusive of any changes made by a statement or transaction with a timestamp equal to the specified parameter. BEFORE refers to the point just before the specified parameter, so with STATEMENT it gives you the table as it stood just before a given query finished.
SELECT ...
FROM ...
{ AT | BEFORE }
(
{ TIMESTAMP => <timestamp> |
OFFSET => <time_difference> |
STATEMENT => <id> |
STREAM => '<name>' }
)
[ ... ]Outside factors. Sometimes the cause isn't in your data at all. Snowflake's ML functions accept exogenous variables, meaning data that may have influenced the target value. The documentation lists weather, holidays, advertisement campaigns and event schedules as typical examples. These can be numeric or categorical, and they can contain NULLs. Collecting them alongside the metric turns guesses such as 'it was the heatwave' into something you can test.
A curated input set. Wrapping the data you collected in a view is common practice. The documentation notes that a view, compared with a table, lets you train models iteratively with different row counts without updating the source data. A view is also where you filter down to the columns your analysis needs.
Checkpoint 2 of 6· Check yourself
An analyst wants a table exactly as it was immediately before a specific UPDATE statement ran, using that statement's query ID. Which clause fits?
BEFORE refers to the point immediately preceding the specified parameter, so it excludes the UPDATE's own changes. AT is inclusive of changes made at that point.
“The BEFORE keyword specifies that the request refers to a point immediately preceding the specified parameter.”Source: docs.snowflake.com
Checkpoint 3 of 6· Exam question
Revenue per order fell 12% in March compared with February. An analyst wants Snowflake to rank which customer segments contributed most to the change using `SNOWFLAKE.ML.TOP_INSIGHTS`. How should the `LABEL_COLNAME` column be populated in the input data?
Correct answer: C — Set it TRUE for March rows, the period being explained, and FALSE for February rows forming the baseline.
- A. Incorrect: a quartile split compares high and low orders, not two periods, so the contributions returned would not explain why the metric dropped between months.
- B. Incorrect: TOP_INSIGHTS compares two time periods or groups itself; it does not need a pre-filtered outlier flag, and an outlier split would not describe the period over period change.
- C. Correct: the label is a Boolean that separates the test group (TRUE) from the control group (FALSE), so March versus February lets GET_DRIVERS attribute the metric change to segments.
- D. Incorrect: the label must be Boolean, not a multi-valued segment name. Segments are discovered automatically from the dimension columns in the input.
3.Analysing trends: downsampling to a useful granularity
Raw time series are often too fine-grained to show a trend. A sensor that reports every second produces a lot of noise and little signal at the scale of days. Downsampling rolls records up to a coarser granularity. You group them into time buckets and summarise each bucket with standard aggregates such as SUM and AVG. Snowflake offers two functions for this. TIME_SLICE works out fixed-width buckets and returns the start of each one. DATE_TRUNC cuts a date or timestamp down to a unit such as day.
Downsampling also matters for collecting related data. When two datasets have different time granularities, they can't be compared row for row. The documentation's example is Sensor A reporting every 15 seconds and Sensor B every 30 seconds. Rolling both up to 1-minute buckets puts them on a shared time axis. IDs and dimensions stay as they are, while the measurements are summed or averaged per interval. It is also a prerequisite for ML-based diagnosis, because the timestamps in your time series must represent fixed time intervals.
| Function | What it does | Example from the docs |
|---|---|---|
| TIME_SLICE | Builds fixed-width buckets and returns each bucket's start time | Per-second sensor readings rolled up to one row per minute per device |
| DATE_TRUNC | Truncates part of a date or timestamp to reduce its granularity | 248M order rows rolled up by day, truck and location to about 500,000 rows |
SELECT DATE_TRUNC('day', order_ts)::date sliced_ts, truck_id, location_id, AVG(order_amount)::NUMBER(4,2) as avg_amount
FROM order_header
WHERE EXTRACT(YEAR FROM order_ts)='2022'
GROUP BY date_trunc('day', order_ts), truck_id, location_id
ORDER BY 1, 2, 3 LIMIT 25;The query above keeps truck_id and location_id in the GROUP BY. That choice is what makes it diagnostic and not just descriptive. If the daily trend dips, the dip can be traced to particular trucks or locations, because the dimensions survived the roll-up.
Checkpoint 4 of 6· Fill the gap
Which function completes this query so that per-second readings become one-minute buckets per device?
SELECT
? (TO_TIMESTAMP_NTZ(timestamp), 1, 'MINUTE') minute_slice,
device_id,
COUNT(*),
AVG(temperature) avg_temp
FROM sensor_data_ts
WHERE TIMESTAMP >= ('2024-03-01 00:01:00')
AND TIMESTAMP < ('2024-03-01 00:02:00')
GROUP BY 1,2
ORDER BY 1,2;TIME_SLICE takes a timestamp, a slice length (1) and a unit ('MINUTE') and returns the start time of each fixed-width bucket. DATE_TRUNC takes the unit first and has no slice-length argument.
Source: docs.snowflake.comSources1
4.Measuring relationships between metrics with CORR
After you collect a candidate cause next to the metric, such as temperature next to sales, the next question is whether the two actually move together. CORR returns the correlation coefficient of a dependent variable y and an independent variable x, calculated as COVAR_POP(y, x) / (STDDEV_POP(x) * STDDEV_POP(y)). It works as an aggregate with GROUP BY, which gives one coefficient per segment. It also works as a window function with OVER (PARTITION BY ...), but in that form it does not allow ORDER BY inside OVER or explicit window frames. DISTINCT is not supported.
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, CORR(v, v2) FROM aggr GROUP BY k;
+---+--------------+
| K | CORR(V, V2) |
|---+--------------|
| 1 | NULL |
| 2 | 0.9988445981 |
+---+--------------+Look at group 2. It has four rows, but the row (25, NULL) is quietly left out, so 0.9988 is based on three pairs. This matters when you compare segments such as regions or customer groups. A segment with a strong coefficient may rest on only a few complete pairs. Before you read a strong coefficient as a strong relationship, count the non-null pairs behind it.
Checkpoint 5 of 6· Check yourself
In the example, why does group 2 return 0.9988 when one of its four rows has v2 = NULL?
The function is defined over non-null pairs, so the incomplete row is left out and the coefficient reflects only the three complete pairs.
“It is computed for non-null pairs using the following formula:”Source: docs.snowflake.com
Checkpoint 6 of 6· Exam question
An analyst runs `GET_DRIVERS` on a table where `store_id` is stored as a NUMBER. The output never lists individual stores as contributors, only numeric ranges. What change makes TOP_INSIGHTS treat each store as a distinct segment?
Correct answer: D — Cast `store_id` to a VARCHAR in the input query so the column is evaluated as a categorical dimension.
- A. Incorrect: the metric column holds the value being explained, such as revenue; putting an identifier there would change what is analyzed rather than how dimensions are typed.
- B. Incorrect: the Boolean column is the label that separates control from test. Turning store_id into a Boolean would destroy the segment information.
- C. Incorrect: clustering affects physical micro-partition layout and scan pruning; it does not change how the function infers the type of a dimension.
- D. Correct: TOP_INSIGHTS infers numeric columns as continuous and strings as categorical, so casting the identifier to a string makes each store a candidate segment.
Sources4
Exam traps
Each one states something that sounds right. Open it to see what is actually true.
1.CORR uses every row in the group, so a high coefficient is backed by all the data in that segment.Why is that wrong?
CORR only uses rows where both x and y are non-null. Rows with a NULL on either side are dropped silently, and a group with no complete pair returns NULL.
Covered in Measuring relationships between metrics with CORR
2.AT and BEFORE with the same STATEMENT ID return the same data.Why is that wrong?
AT includes changes made by the statement or transaction at the specified point, while BEFORE returns the state just before it, without that statement's changes.
Sources
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“facts that might reveal trends or anomalies in the data”
↩︎ What you are diagnosing: anomalies and patterns in historical data“A time series might reveal spikes when readings change dramatically for some reason.”
↩︎ What you are diagnosing: anomalies and patterns in historical data“the view option gives you some flexibility to train models iteratively, with different row counts, without updating the source data.”
↩︎ Collecting the related data a diagnosis needs“you can roll up these records to a coarser granularity, effectively producing a smaller sample.”
↩︎ Analysing trends: downsampling to a useful granularity“aggregating the records into 1-minute buckets might be a good solution”
↩︎ Analysing trends: downsampling to a useful granularity“For machine-learning purposes, the timestamps in your time series must represent fixed time intervals.”
↩︎ Analysing trends: downsampling to a useful granularity“Dimensions of interest that are associated with the measurement”
↩︎ Key concept“Dimensions of interest that are associated with the measurement”
↩︎ Checkpoint - 2.
“The AT or BEFORE clause is used for Snowflake Time Travel.”
↩︎ Collecting the related data a diagnosis needs“The value must be explicitly cast to a TIMESTAMP, TIMESTAMP_LTZ, TIMESTAMP_NTZ, or TIMESTAMP_TZ data type.”
↩︎ Collecting the related data a diagnosis needs“the request is inclusive of any changes made by a statement or transaction with a timestamp equal to the specified parameter”
↩︎ Exam trap 2“The BEFORE keyword specifies that the request refers to a point immediately preceding the specified parameter.”
↩︎ Checkpoint - 3.
“Appropriate exogenous variables could include weather data (temperature, rainfall), company-specific information (historic and planned company holidays, advertisement campaigns, event schedules)”
↩︎ Collecting the related data a diagnosis needs - 4.
“Where x is the independent variable and y is the dependent variable.”
↩︎ Measuring relationships between metrics with CORR“DISTINCT is not supported for this function.”
↩︎ Measuring relationships between metrics with CORR“Returns the correlation coefficient for non-null pairs in a group.”
↩︎ Exam trap 1“Returns the correlation coefficient for non-null pairs in a group.”
↩︎ Prediction“It is computed for non-null pairs using the following formula:”
↩︎ Checkpoint