---
title: "Measuring AB Tests: SQL for p-value graphs in Redshift"
description: SQL to do p-values and significance calculation in Redshift
---

[ezCater Engineering & Product Blog](https://engineering.ezcater.com)

# [Measuring AB Tests: SQL for p-value graphs in Redshift](https://engineering.ezcater.com/measuring-ab-tests-sql-for-pvalue-graphs-in-redshift)

 Written by [Jeff Dwyer](https://engineering.ezcater.com/author/jeff-dwyer) | Jun 1

So, in [deciding when an AB test is actionable using p-value graphs](https://engineering.ezcater.com/deciding-when-to-call-an-ab-test-p-value-graphs) we saw some cool charts that looked like:

In these charts the green line is "cumulative p-value" and the red and blue track "conversions".  This example is a "definitely not significant" experiment.

So how do we get our [redshift event schema](https://engineering.ezcater.com/ezexperiments-ab-testing-at-ezcater-part-1-event-taxonomy-warehousing) to lead to something that looks like this? Let's take a look at the SQL.

First we need to find our Exposure and Conversion events.

 

Then we calculate the daily conversions.

 

Then we make them cumulative using some window functions.

 

Then some grouping up to make it tidy. 

 

Finally we run a significance function for each day.

 

Here's the definition of the significance function from the wonderful [Periscope Blog](https://www.periscopedata.com/blog/ab-testing-in-redshift.html).

 

And that's it! We use the heck out of [Periscope](https://www.periscopedata.com) for visualizing and sharing these reports with others. We just need to configure things a little bit in there so that the conversion lines end up on a second y-axis. 

 

[View full post](https://engineering.ezcater.com/measuring-ab-tests-sql-for-pvalue-graphs-in-redshift)

```json
{
  "@context" : "http://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Jeff Dwyer"
  },
  "dateModified" : "2017-06-01T19:59:01.990Z",
  "datePublished" : "2017-06-01T17:15:28Z",
  "headline" : "Measuring AB Tests: SQL for p-value graphs in Redshift",
  "image" : {
    "@type" : "ImageObject",
    "height" : 632,
    "url" : "https://cdn2.hubspot.net/hubfs/1703639/devblog/Screen%20Shot%202017-04-18%20at%209.44.39%20AM.png",
    "width" : 1920
  },
  "mainEntityOfPage" : "https://engineering.ezcater.com/measuring-ab-tests-sql-for-pvalue-graphs-in-redshift",
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "height" : 60.0,
      "url" : "https://cdn2.hubspot.net/hubfs/1703639/ezCater%20Logo%20-%20Normal.png",
      "width" : 259.90784
    },
    "name" : "ezCater Engineering & Product Blog"
  }
}
```