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, 1 Nov, 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

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

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

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

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

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.

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

Adblock Detection