Homeโ€บQuery Libraryโ€บShopify

Which products are your stars, which are your dogs?

The product performance matrix combines revenue, units sold, refund rate, and repeat purchase contribution into a single ranked view. Identify your best and worst performers at a glance.

๐Ÿ“Š Shopify๐Ÿ‘ฅ Shopify merchants and operations teams๐Ÿ”ค Plain-English โ†’ SQL

This is part of the Taptic Data Shopify query library. Explore related queries: SQL query for Shopify revenue by month, SQL query for Shopify customer lifetime value, SQL query for Shopify refund rate by product, and more.

Show me a product performance matrix with revenue, units, refund rate, and repeat buyer percentage
โ†“
Shopify Product Performance Matrix โ€” generated by Taptic Data AI
WITH product_sales AS (
  SELECT
    li.product_id,
    MAX(li.title)                               AS product_name,
    SUM(li.quantity)                            AS units_sold,
    ROUND(SUM(li.price * li.quantity)::numeric, 2) AS revenue,
    COUNT(DISTINCT o.customer_id)              AS unique_buyers
  FROM shopify_order_line_items li
  JOIN shopify_orders o ON o.id = li.order_id
  WHERE o.financial_status IN ('paid', 'partially_refunded')
    AND o.cancelled_at IS NULL
    AND o.created_at >= NOW() - INTERVAL '90 days'
  GROUP BY li.product_id
),
product_refunds AS (
  SELECT
    li.product_id,
    SUM(li.quantity)                            AS units_refunded
  FROM shopify_refunds r
  JOIN shopify_order_line_items li ON li.order_id = r.order_id
  WHERE r.created_at >= NOW() - INTERVAL '90 days'
  GROUP BY li.product_id
),
repeat_buyers AS (
  SELECT product_id, COUNT(DISTINCT customer_id) AS repeat_count
  FROM (
    SELECT li.product_id, o.customer_id
    FROM shopify_order_line_items li
    JOIN shopify_orders o ON o.id = li.order_id
    WHERE o.financial_status IN ('paid', 'partially_refunded')
      AND o.cancelled_at IS NULL
    GROUP BY li.product_id, o.customer_id
    HAVING COUNT(DISTINCT o.id) > 1
  ) sub
  GROUP BY product_id
)
SELECT
  ps.product_name,
  ps.revenue,
  ps.units_sold,
  ps.unique_buyers,
  COALESCE(pr.units_refunded, 0)               AS units_refunded,
  ROUND(COALESCE(pr.units_refunded, 0)::numeric * 100
    / NULLIF(ps.units_sold, 0), 1)             AS refund_rate_pct,
  COALESCE(rb.repeat_count, 0)                 AS repeat_buyers,
  ROUND(COALESCE(rb.repeat_count, 0)::numeric * 100
    / NULLIF(ps.unique_buyers, 0), 1)          AS repeat_buyer_pct
FROM product_sales ps
LEFT JOIN product_refunds pr USING (product_id)
LEFT JOIN repeat_buyers rb USING (product_id)
WHERE ps.units_sold >= 10
ORDER BY ps.revenue DESC
LIMIT 30
Schema-aware SQL generated from plain English53 lines

This query was generated by Taptic Data from plain English against a real Shopify schema. In Taptic, you type the question โ€” the AI writes the SQL, runs it, and returns the result. You can edit the SQL, ask for explanations, and save it as a refreshable report.

Breaking it down line by line

  1. CTE "product_sales" calculates revenue, units, and unique buyers per product from order line items
  2. CTE "product_refunds" counts refunded units per product from the refunds table
  3. CTE "repeat_buyers" identifies how many customers bought a product more than once
  4. The final SELECT combines all three dimensions into one view with both rates calculated
  5. Products with high revenue, low refund rate, and high repeat buyer percentage are your stars

Result description

Per-product performance view with revenue, units, refund rate, unique buyers, and repeat buyer percentage โ€” your complete product health scorecard.

The business impact

Revenue alone does not tell you which products are healthy. A product doing $50K but with 12% refund rate and 5% repeat buyers is a liability disguised as success. The performance matrix reveals the complete picture so you can invest in the right products.

Common questions

How do I generate a "Shopify Product Performance Matrix" query automatically?
In Taptic Data, type "Show me a product performance matrix with revenue, units, refund rate, and repeat buyer percentage" and the AI generates schema-aware SQL against your real Shopify data โ€” no manual writing required.
What database does this query work with?
This query is designed for Shopify. Taptic reads your live schema so the generated SQL always matches your actual table and column names.
Can I edit the generated SQL?
Yes. Taptic shows you the exact SQL it generated. You can edit it directly, ask the AI to explain any line, or request a revision in plain English.
Can I save this as a scheduled report?
Yes. Once you run this query in Taptic, you can save it as a report, add charts and KPIs, and schedule it to email your team on any cadence โ€” daily, weekly, or monthly.

Skip the SQL. Ask the question.

In Taptic Data, you type "Show me a product performance matrix with revenue, units, re..." and this SQL runs automatically against your real Shopify data.

Try Taptic Free โ€” $29.99/mo

No credit card required. Connect your data source in under 5 minutes.