Template

Influenced-pipeline query

Last updated

From Section 15.3. A simple SQL sketch that attributes opportunities to plays that touched the account in the 90 days before the opportunity was created.

A simple SQL sketch that attributes opportunities to plays that touched the account in the 90 days before the opportunity was created.

Table and column names are examples. The cutoff date 2026-07-01 is example data; replace it with the start of your reporting window. This is play-level influence, not a claim that the play caused the opportunity (Chapter 15).

-- Influenced pipeline by play: any play that touched the account
-- in the 90 days before the opportunity was created.
-- The cutoff date below is example data.
with opp as (
  select opp_id, account_id, created_at, amount
  from fct_opportunities
  where created_at >= date '2026-07-01'
),
touches as (
  select distinct o.opp_id, o.amount, a.play_id
  from opp o
  join fct_activities a
    on a.account_id = o.account_id
   and a.play_id is not null
   and a.occurred_at between o.created_at - interval '90 days' and o.created_at
)
select
  play_id,
  count(*)    as opps_influenced,
  sum(amount) as pipeline_influenced
from touches
group by play_id
order by pipeline_influenced desc;