Fivetran to Acquire HVR; Announces $565M in Series D. Learn More.

HomeBlog
Funnel Analysis and Conversion Metrics in SQL
Fivetran
HomeBlog
Funnel Analysis and Conversion Metrics in SQL

Funnel Analysis and Conversion Metrics in SQL

Using SQL to conduct funnel analysis can help you make sense of multiple facets of your business.

By Charles Wang, November 1, 2018

Try it with connectors from Salesforce, Greenhouse, Shopify and more.

Funnel analysis crops up everywhere. It can be used to analyze success of sales and marketing teams, a customer's progression through a website, or the efficiency of a recruiting pipeline. A famous example in the startup world is David McClure’s AARRR (pirate) framework for product metrics. In general, it is a useful approach to analyzing just about any process that involves multiple steps and attrition.

Some Example Data

Let’s walk through an example involving some mock sales data. In our sales model, we have the following progression of events:

  1. Lead - a potential client has been identified

  2. Marketing Qualified - the marketing team has determined that a potential client is a good fit, based on broad characteristics

  3. Sales Qualified - the sales team has determined that potential client is a good fit, based on conversations with the client

  4. Negotiated - the sales team has discussed pricing and features with a potential client

  5. Customer - the sales team has closed new business with client

  6. Renewed - the client has renewed their contract for the next period

The particulars of a funnel can vary. In the actual Salesforce schema, you will likely be looking at the “opportunity_history” table, and examining steps with names like “contacted,” “qualified,” and “won.” What is most important to making this model work is that the expected value of a client increases as they progress down the funnel, while the raw number of clients decreases.

We’ll use a table with the following fields:

  1. account_id - a unique identifier for client accounts

  2. date - date on which an event occurred

  3. event - type of event, from the above progression

account_iddateevent
0000331/5/2018lead
0000632/28/2019negotiated
0000502/5/2018sales_qualified
0000016/18/2018lead
00005311/12/2018lead
0000912/14/2019negotiated

The “events” table contains only accounts that were opened in fiscal year 2018. Cohort analysis is a subject for another post.

Queries

The simplest thing you might consider doing is this:

SELECT event, COUNT(*) as event_count FROM samplesales.events GROUP BY event ORDER BY COUNT(*) DESC

eventevent_count
lead153
marketing_qualified71
sales_qualified29
negotiated13
registered5
renewed2

A straightforward aggregation, and a great start for getting the absolute magnitudes of each step. But what if we want percentages?

WITH grouped_events as (SELECT event, COUNT(*) as event_count FROM samplesales.events GROUP BY event) SELECT event, event_count, event_count/(SELECT MAX(event_count) FROM grouped_events) as event_percentage FROM grouped_events ORDER BY event_count DESC

eventevent_countevent_percentage
lead1531.0
marketing_qualified710.4650
sales_qualified290.1895
negotiated130.0850
registered50.0327
renewed20.0131

We’ve turned the first query into a common table expression, and then referred to a specific value from it. And what if we want to measure the percentage of prospective clients who are lost at each step.? We add a window function called “lag” that returns the preceding data for each row.

WITH grouped_events as (SELECT event, COUNT(*) as event_count FROM samplesales.events GROUP BY event) SELECT event, event_count, event_count/(SELECT MAX(event_count) FROM grouped_events) as total_percentage, lag(event_count, 1) over (ORDER BY event_count DESC) as above_count FROM grouped_events ORDER BY event_count DESC

eventevent_counttotal_percentageabove_count
lead1531.0
marketing_qualified710.4650153
sales_qualified290.189571
negotiated130.085029
customer50.032713
renewed20.01315

Then, let’s divide event_count by above_count to get the percentage of clients who convert between each step in the funnel:

WITH grouped_events as (SELECT event, COUNT(*) as event_count FROM samplesales.events GROUP BY event) SELECT event, event_count, event_count/(SELECT MAX(event_count) FROM grouped_events) as total_percentage, event_count/lag(event_count, 1) over (ORDER BY event_count DESC) as percentage_survival_by_step FROM grouped_events ORDER BY event_count DESC

eventevent_counttotal_percentagepercentage_survival_by_step
lead1531.0
marketing_qualified710.46500.4650
sales_qualified290.18950.4084
negotiated130.08500.4483
customer50.03270.3846
renewed20.01310.4000

Note that, at about 38%, the transition from negotiation to registration is proportionally the most serious choke point in the funnel, although serious attrition takes place at every step. An impactful intervention here might be to focus on changing negotiation tactics used by our sales team.

Going Forward

Fivetran offers connectors across a range of business operations. Funnel analysis is one method among several that, combined with multiple connectors, will allow you to build a comprehensive representation of how your company is performing in matters of marketing, sales, customer success, recruiting, and more.

Check out a demo of Fivetran so that we can help you bring data literacy to every facet of your business.

Start analyzing your data in minutes, not months

Launch any Fivetran connector instantly.