Skip to main content

Contribution Explorer and Top Insights

What Is Contribution Explorer?​

SNOWFLAKE.ML.CONTRIBUTION_EXPLORER identifies which dimensions (categorical columns) contribute most to a change in a metric. When a KPI moves unexpectedly — revenue drops, error rates spike, conversion decreases — Contribution Explorer pinpoints the segments driving the shift.

What Is Top Insights?​

SNOWFLAKE.ML.TOP_INSIGHTS is a streamlined function that wraps Contribution Explorer into a single call. It compares two groups of data (e.g., this week vs last week) and returns the top contributing segments ranked by impact.

When to Use These Functions​

ScenarioFunction
Revenue dropped 15% week-over-week — why?Top Insights or Contribution Explorer
Conversion rate changed after a deploymentContribution Explorer
Support ticket volume spiked — which categories?Top Insights
Ad spend ROI declined — which campaigns?Contribution Explorer

Data Requirements​

The input data must contain:

Column TypeDescriptionExample
Metric columnThe numeric value that changedrevenue, error_count, conversion_rate
Dimension columnsCategorical attributes to analyzeregion, product, channel, device_type
Label columnIdentifies the two groups to compareperiod = 'current' vs period = 'previous'

Using Top Insights​

-- Prepare comparison data with a label column
CREATE OR REPLACE VIEW revenue_comparison AS
SELECT
region,
product_category,
customer_segment,
channel,
revenue,
CASE
WHEN sale_date BETWEEN '2024-07-01' AND '2024-07-31' THEN 'CURRENT'
WHEN sale_date BETWEEN '2024-06-01' AND '2024-06-30' THEN 'PREVIOUS'
END AS period
FROM daily_sales
WHERE period IS NOT NULL;

-- Run Top Insights
CALL SNOWFLAKE.ML.TOP_INSIGHTS(
INPUT_DATA => SYSTEM$REFERENCE('VIEW', 'REVENUE_COMPARISON'),
METRIC_COLNAME => 'REVENUE',
LABEL_COLNAME => 'PERIOD',
LABEL_VALUE_OF_INTEREST => 'CURRENT'
);

Top Insights Output​

The result ranks contributing segments:

ColumnDescription
CONTRIBUTORThe dimension value(s) driving the change
METRIC_CURRENTMetric value in the current period
METRIC_PREVIOUSMetric value in the previous period
RELATIVE_CHANGEPercentage change for this segment
OVERALL_RELATIVE_CHANGEPercentage change across all data
GROWTH_RATEHow much this segment's growth differs from overall
SURPRISEStatistical measure of how unexpected this change is
-- Review the top contributors
SELECT * FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
ORDER BY surprise DESC
LIMIT 10;

Using Contribution Explorer​

Contribution Explorer provides more control over the analysis:

-- Create the explorer object
CREATE OR REPLACE SNOWFLAKE.ML.CONTRIBUTION_EXPLORER revenue_explorer(
INPUT_DATA => SYSTEM$REFERENCE('VIEW', 'REVENUE_COMPARISON'),
METRIC_COLNAME => 'REVENUE',
LABEL_COLNAME => 'PERIOD',
LABEL_VALUE_OF_INTEREST => 'CURRENT'
);

-- Get top contributors
CALL revenue_explorer!GET_CONTRIBUTIONS();

Practical Example: Revenue Drop Analysis​

-- Revenue dropped 20% this month. Find out why.

-- Step 1: Prepare the comparison dataset
CREATE OR REPLACE VIEW revenue_investigation AS
SELECT
r.region,
r.country,
p.category AS product_category,
c.segment AS customer_segment,
o.channel,
o.revenue,
CASE
WHEN o.order_date BETWEEN '2024-08-01' AND '2024-08-31' THEN 'CURRENT'
WHEN o.order_date BETWEEN '2024-07-01' AND '2024-07-31' THEN 'PREVIOUS'
END AS period
FROM orders o
JOIN regions r ON o.region_id = r.id
JOIN products p ON o.product_id = p.id
JOIN customers c ON o.customer_id = c.id
WHERE period IS NOT NULL;

-- Step 2: Run the analysis
CALL SNOWFLAKE.ML.TOP_INSIGHTS(
INPUT_DATA => SYSTEM$REFERENCE('VIEW', 'REVENUE_INVESTIGATION'),
METRIC_COLNAME => 'REVENUE',
LABEL_COLNAME => 'PERIOD',
LABEL_VALUE_OF_INTEREST => 'CURRENT'
);

-- Step 3: Interpret results
SELECT
contributor,
ROUND(relative_change * 100, 1) AS segment_change_pct,
ROUND(overall_relative_change * 100, 1) AS overall_change_pct,
ROUND(surprise, 3) AS surprise_score
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
ORDER BY surprise DESC
LIMIT 15;

Example output interpretation:

ContributorSegment ChangeOverall ChangeSurprise
region = 'EMEA'-38.2%-20.1%0.872
product_category = 'Enterprise'-45.1%-20.1%0.814
region = 'EMEA' AND product_category = 'Enterprise'-62.3%-20.1%0.791

This tells us: EMEA Enterprise revenue dropped 62%, far exceeding the overall 20% decline. This combination is the primary driver.

Practical Example: KPI Investigation​

-- Error rate spiked after a release — which services are affected?
CREATE OR REPLACE VIEW error_rate_investigation AS
SELECT
service_name,
endpoint,
http_status_code,
deployment_region,
error_count,
CASE
WHEN log_date = CURRENT_DATE() THEN 'CURRENT'
WHEN log_date = DATEADD('day', -1, CURRENT_DATE()) THEN 'PREVIOUS'
END AS period
FROM daily_service_metrics
WHERE period IS NOT NULL;

CALL SNOWFLAKE.ML.TOP_INSIGHTS(
INPUT_DATA => SYSTEM$REFERENCE('VIEW', 'ERROR_RATE_INVESTIGATION'),
METRIC_COLNAME => 'ERROR_COUNT',
LABEL_COLNAME => 'PERIOD',
LABEL_VALUE_OF_INTEREST => 'CURRENT'
);

Best Practices​

  1. Include diverse dimensions — The more categorical columns you provide, the more specific the insights. Include region, product, channel, segment, and other relevant breakdowns.
  2. Compare like for like — Ensure the two periods are comparable (same number of business days, no holidays skewing one period).
  3. Focus on the SURPRISE column — High surprise indicates segments that changed disproportionately relative to the overall trend.
  4. Drill down iteratively — If the top contributor is a broad category (e.g., region = 'APAC'), create a new analysis scoped to that region with more granular dimensions.
  5. Automate investigations — Schedule Top Insights as a Snowflake Task to run after each reporting cycle, storing results for review.