← Portfolio
</>
SQL Methodology

GTM Metric Calculations

The SQL behind every metric in the NorthStar governance framework. Each query includes the calculation logic, edge case handling, and documentation of how cross-team definition conflicts were resolved.

Written for Snowflake SQL dialect · Assumes Salesforce + billing system as source · All queries are dbt-model-ready

Qualified PipelinePipeline
Total ACV of open opportunities at Stage 2+ (Qualified or later).

Total ACV of open opportunities at Stage 2+ (Qualified or later). This is the single most contested metric in GTM analytics — Sales, Marketing, and Finance almost always define it differently. The SQL below implements the Rev Ops standard: stage-gated, excludes closed deals, and uses the current ACV field (not the original estimate).

-- Qualified Pipeline: Current ACV of all open opportunities at Stage 2+
-- Owner: Rev Ops | Refresh: Daily 6:00 AM ET | Source: Salesforce Opportunity
WITH stage_map AS (
SELECT stage_name,
CASE stage_name
WHEN 'Prospecting' THEN 1
WHEN 'Qualified' THEN 2
WHEN 'Demo' THEN 3
WHEN 'Proposal' THEN 4
WHEN 'Negotiation' THEN 5
WHEN 'Closed Won' THEN 6
WHEN 'Closed Lost' THEN 7
END AS stage_order
FROM salesforce.opportunity
)
SELECT
o.owner_name AS rep,
a.specialty_segment AS specialty,
o.lead_source AS source_channel,
COUNT(DISTINCT o.opportunity_id) AS deal_count,
SUM(o.acv) AS pipeline_acv,
AVG(o.acv) AS avg_deal_size,
MEDIAN(o.acv) AS median_deal_size
FROM salesforce.opportunity o
JOIN salesforce.account a
ON o.account_id = a.account_id
JOIN stage_map sm
ON o.stage_name = sm.stage_name
WHERE sm.stage_order BETWEEN 2 AND 5 -- Qualified through Negotiation
AND o.is_closed = FALSE -- Exclude won and lost
AND o.acv >= 5000 -- Floor: exclude sub-$5K trials
AND o.is_deleted = FALSE
GROUP BY 1, 2, 3
ORDER BY pipeline_acv DESC;
Edge Cases & Guards
·Excludes Prospecting (Stage 1) — these haven't been validated by Sales yet
·Excludes deals < $5K to filter out free trials and POCs that inflate pipeline count
·Uses current ACV, not original — captures upsells and downsells during negotiation
·The is_deleted check catches Salesforce soft-deletes that can silently inflate totals
Definition Conflicts & Resolution

Sales wants to include Stage 1 (Prospecting) to show larger pipeline. Marketing wants to include MQLs that haven't converted to Opportunity yet. Finance wants Stage 3+ only (post-demo). The resolved standard uses Stage 2+ as the compromise — validated by Sales but not yet requiring a completed demo.

Win Rate by SegmentSales Efficiency
Win rate is deceptively simple until you define the denominator.
Sales Cycle VelocitySales Efficiency
Median days from opportunity creation to close, segmented by deal size tier.
Marketing Attribution — Pipeline SourcedMarketing Attribution
The most politically sensitive metric in any GTM org.
Net Revenue Retention (NRR)Customer Success
NRR tells you whether your existing customers are growing or shrinking as a revenue base.
Implementation Notes

These queries are written for Snowflake SQL and designed to be implemented as dbt models with schema tests (not_null, unique, accepted_values) and freshness checks. In production, each metric would be a dbt model in a marts/gtm_analytics/ directory with a corresponding YAML schema file documenting the column definitions, tests, and metadata. The conflict resolution notes map directly to the NorthStar Metric Registry — each resolved conflict becomes a documented decision in the governance layer.