xmetric / Use cases

Analyze Shopify Discount Code Usage and Revenue Leakage from CSV

To audit Shopify discount codes and revenue erosion from orders_export.csv, deduplicate the order-level Discount Amount across line items, rank every Discount Code by total discount given and net sales, and compare repeat purchase rates between discounted and full-price buyers. The formulas and equivalent SQL are below; xmetric builds the view in your browser.

Chart your own CSV

Chart your export here

Drop a CSV here. xmetric reads every row in this browser and draws a first chart you can regroup or change the measure of. Nothing is uploaded.

No file loaded yet. You can also drop a CSV on this box.

How to export discount and order data from Shopify

  1. In your Shopify Admin, go to Orders.
  2. Click Export, select All orders (or your campaign date window), and choose CSV for Excel, Numbers, or other spreadsheet programs.
  3. Download orders_export.csv. Drop it above for a first chart, or import it into the xmetric app to build the discount audit.

Shopify CSV columns used for discount analysis

Tableau LOD formulas and SQL for discount code audits

You can test each formula below in the formula playground before building the view.

1. Deduplicated Order Discount and Gross Merchandise Value (FIXED LOD)

Because Shopify prints Discount Code, Discount Amount, and Subtotal on the first row of each order Name, wrap order-level measures in a { FIXED [Name] } expression:

// [Order Discount Amount]
{ FIXED [Name] : MAX(IFNULL([Discount Amount], 0)) }

// [Order Net Subtotal]
{ FIXED [Name] : MAX(IFNULL([Subtotal], 0)) }

// [Order Gross Value Before Discount]
[Order Net Subtotal] + [Order Discount Amount]

2. Effective Discount Rate %

// [Effective Discount %]
SUM([Order Discount Amount]) / SUM([Order Gross Value Before Discount])

3. Do Discount Buyers Ever Return? (SQL equivalent)

This equivalent SQL shows not just how much each Discount Code cost you in margin, but whether those buyers ever placed a 2nd order:

WITH orders_deduped AS (
  SELECT
    "Name" AS order_name,
    LOWER(TRIM("Email")) AS customer_email,
    MIN(CAST("Created at" AS TIMESTAMP)) AS order_at,
    COALESCE(NULLIF(UPPER(TRIM(MAX("Discount Code"))), ''), '(No Discount)') AS discount_code,
    MAX(CAST(COALESCE(NULLIF("Discount Amount", ''), '0') AS DOUBLE)) AS discount_amount,
    MAX(CAST(COALESCE(NULLIF("Subtotal", ''), '0') AS DOUBLE)) AS net_subtotal
  FROM shopify_orders
  WHERE "Email" IS NOT NULL AND TRIM("Email") <> ''
  GROUP BY 1, 2
),
customer_orders AS (
  SELECT
    *,
    ROW_NUMBER() OVER (PARTITION BY customer_email ORDER BY order_at, order_name) AS order_num,
    COUNT(*) OVER (PARTITION BY customer_email) AS customer_lifetime_orders
  FROM orders_deduped
)
SELECT
  discount_code,
  COUNT(DISTINCT order_name) AS total_orders,
  ROUND(SUM(net_subtotal + discount_amount), 2) AS gross_sales,
  ROUND(SUM(discount_amount), 2) AS total_discount_given,
  ROUND(SUM(net_subtotal), 2) AS net_sales,
  ROUND(100.0 * SUM(discount_amount) / NULLIF(SUM(net_subtotal + discount_amount), 0), 1) AS effective_discount_pct,
  ROUND(AVG(net_subtotal), 2) AS net_aov,
  ROUND(
    100.0 * COUNT(DISTINCT CASE WHEN order_num = 1 AND customer_lifetime_orders >= 2 THEN customer_email END)
    / NULLIF(COUNT(DISTINCT CASE WHEN order_num = 1 THEN customer_email END), 0),
    1
  ) AS first_order_repeat_rate_pct
FROM customer_orders
GROUP BY 1
ORDER BY total_discount_given DESC;

Spotting leaked influencer and welcome codes

Audit promo margin with coding agents

Every action in xmetric is a command. An MCP server for Claude and ChatGPT is in development, so your assistant will be able to audit promo leakage in a Shopify CSV. Live connections to Postgres and BigQuery are also coming.

Questions people ask

Does Shopify's `Subtotal` column exclude shipping and taxes?

Yes. In orders_export.csv, Subtotal represents the order's product subtotal after discounts and before Shipping and Taxes, while Discount Amount records the discount applied to the order.

How do I compare AOV with a discount code vs. without a discount code?

Group [Discount Code] into two buckets with a calculated field: Discounted ([Order Discount Amount] > 0) versus Full Price ([Order Discount Amount] = 0). Put that field on Columns in the xmetric app next to average order value.

Is my Shopify orders file uploaded anywhere?

No. xmetric reads CSV files directly inside your browser, unless you sign in and choose to save a workbook online. The xmetric app also imports Excel (.xlsx) and Parquet files.

Drop your orders_export.csv above for a first chart, then build the full promo code audit in the xmetric app.