Skip to content

Guide · Shopify analytics

ShopifyQL query examples for common store questions

ShopifyQL is Shopify's report language. A query starts with FROM and a schema such as sales, customers, inventory or sessions, then SHOW and the metrics you want, then GROUP BY or TIMESERIES and a date range. The queries below answer everyday merchant questions and run in the query editor at the top of any Analytics report.

How is a ShopifyQL query put together?

ShopifyQL is not SQL. There is no SELECT and no joins: you pick one schema with FROM, list its metrics with SHOW, and slice them by a dimension with GROUP BY or by time with TIMESERIES. Each schema has its own columns, so a metric from the sales schema won't work in the inventory schema. Shopify's ShopifyQL reference lists every schema with its metrics and dimensions.

Write the clauses in the order below. Text values go in single quotes, such as WHERE human_or_bot_session = 'human'. WHERE filters rows before they are added up; HAVING filters on a metric after they are.

The main clauses, in order
ClauseWhat it doesExample
FROMPicks the schemaFROM sales
SHOWLists the metricsSHOW total_sales, orders
WHEREFilters rows by a dimensionWHERE discount_code IS NOT NULL
GROUP BY or TIMESERIESSplits by a dimension, or by day, week or monthGROUP BY product_title
SINCE and UNTIL, or DURINGSets the date rangeSINCE -30d UNTIL today, or DURING last_month
COMPARE TOAdds a comparison periodCOMPARE TO previous_period
HAVINGFilters on a metricHAVING inventory_units_sold = 0
ORDER BY and LIMITSorts and caps the rowsORDER BY total_sales DESC LIMIT 10

Which ShopifyQL queries answer sales questions?

All of these use the sales schema. Paste one into the editor, then change the dates or the LIMIT to suit.

Sales and product queries
QuestionQuery
How have sales, orders and AOV moved month by month this year?FROM sales SHOW total_sales, orders, average_order_value TIMESERIES month SINCE -12m UNTIL today
How did last month compare with the month before?FROM sales SHOW total_sales, orders, average_order_value DURING last_month COMPARE TO previous_period
How did last quarter's weeks compare with the same weeks a year earlier?FROM sales SHOW total_sales TIMESERIES week DURING last_quarter COMPARE TO previous_year
What were my top 10 products by sales in the last 30 days?FROM sales SHOW net_items_sold, total_sales GROUP BY product_title SINCE -30d UNTIL today ORDER BY total_sales DESC LIMIT 10
Which variants sold the most units?FROM sales SHOW net_items_sold, total_sales GROUP BY product_title, product_variant_title SINCE -30d UNTIL today ORDER BY net_items_sold DESC LIMIT 20
Which day of the week sells best?FROM sales SHOW total_sales, orders GROUP BY day_of_week SINCE -90d UNTIL today ORDER BY total_sales DESC
Which discount codes drove the most sales?FROM sales SHOW orders, total_sales, net_items_sold WHERE discount_code IS NOT NULL GROUP BY discount_code SINCE -30d UNTIL today ORDER BY total_sales DESC LIMIT 20
Which channels bring new and returning buyers?FROM sales SHOW total_sales, orders, new_customers, returning_customers GROUP BY referring_channel SINCE -90d UNTIL today ORDER BY total_sales DESC
Which products earn the most gross profit?FROM sales SHOW net_sales, cost_of_goods_sold, gross_profit, gross_margin WHERE cost_is_recorded = true GROUP BY product_title SINCE -90d UNTIL today ORDER BY gross_profit DESC LIMIT 20
Which products have the most returned or reversed units?FROM sales SHOW quantity_ordered, reversed_quantity, reversed_quantity_rate GROUP BY product_title SINCE -90d UNTIL today ORDER BY reversed_quantity DESC LIMIT 20

Which ShopifyQL queries answer customer questions?

Customer questions use two schemas. The sales schema counts customers who ordered in the date range. The customers schema describes customer records, including how many orders each has placed in total.

Customer queries
QuestionQuery
What share of each month's buyers had bought before?FROM sales SHOW customers, returning_customers, returning_customer_rate TIMESERIES month SINCE -12m UNTIL today
How many orders do my customers place in total?FROM customers SHOW percent_of_customers WHERE customer_number_of_orders >= 1 GROUP BY customer_number_of_orders ORDER BY customer_number_of_orders ASC
How do Shopify's RFM groups compare on orders and spend?FROM customers SHOW total_number_of_orders, total_amount_spent, days_since_last_order GROUP BY rfm_group ORDER BY total_amount_spent DESC

Which ShopifyQL queries answer inventory and conversion questions?

Inventory questions use the inventory schema, which works per variant and only goes back to October 2023. Conversion questions use the sessions schema, which counts online store visits.

Inventory and conversion queries
QuestionQuery
Which tracked variants sold nothing in 90 days but still have stock?FROM inventory SHOW ending_inventory_units, inventory_units_sold, ending_inventory_value WHERE inventory_is_tracked = true GROUP BY product_title, product_variant_title SINCE -90d UNTIL today HAVING inventory_units_sold = 0 AND ending_inventory_units > 0 ORDER BY ending_inventory_value DESC LIMIT 100
Which variants have more than 90 days of stock at the current pace?FROM inventory SHOW ending_inventory_units, inventory_units_sold_per_day, days_of_inventory_remaining, sell_through_rate WHERE inventory_is_tracked = true GROUP BY product_title, product_variant_title DURING last_month HAVING days_of_inventory_remaining > 90 ORDER BY days_of_inventory_remaining DESC LIMIT 50
How does my store funnel move week by week?FROM sessions SHOW sessions, sessions_with_cart_additions, sessions_that_reached_checkout, sessions_that_completed_checkout, conversion_rate WHERE human_or_bot_session = 'human' TIMESERIES week SINCE -90d UNTIL today
Do mobile visitors convert worse than desktop?FROM sessions SHOW sessions, added_to_cart_rate, reached_checkout_rate, conversion_rate GROUP BY session_device_type SINCE -30d UNTIL today
Which product landing pages get visits but few sales?FROM sessions SHOW sessions, added_to_cart_rate, conversion_rate WHERE landing_page_type = 'Product' AND human_or_bot_session = 'human' GROUP BY landing_page_path SINCE -30d UNTIL today HAVING sessions > 100 ORDER BY sessions DESC LIMIT 25

Why does a ShopifyQL query fail or return odd numbers?

Most errors and surprises come from a handful of causes.

  • A 'column not found' error usually means the metric belongs to a different schema. Check the schema's page in Shopify's reference rather than guessing a name.
  • Text values need single quotes, and they are matched exactly, so 'Product' and 'product' are different values.
  • total_sales adds shipping and taxes on top of net_sales. Pick one and stick with it when you compare periods.
  • days_of_inventory_remaining is empty for a variant that sold nothing in the range, so zero sellers need their own query.
  • Sessions include bot traffic unless you filter on human_or_bot_session.
  • Order counts can differ slightly from your Orders page, because reports and the order list treat edits, returns and timing in different ways.

How do you run a ShopifyQL query in the Shopify admin?

The query editor sits at the top of every report in Shopify's Analytics.

  1. In the Shopify admin, open Analytics, then Reports, and open any report.
  2. Find the ShopifyQL query editor at the top of the report. It shows the query behind the report you opened.
  3. Replace the query with one from the tables above and run it. The table and chart below update to match.
  4. Change the date range in the query (SINCE, UNTIL or DURING) rather than with the date picker, so the query stays the source of truth.
  5. If Shopify reports an error, check the column names against the schema's reference page and the clause order above.
  6. Save it as a custom report if your plan allows it (Shopify says custom reports need Advanced or Plus), or export the results.

How does Datae use ShopifyQL?

You don't need to write ShopifyQL to use it. Ask Datae a question in plain words, and when its standard Shopify tools don't cover it, Datae writes a ShopifyQL query, runs it against your store and reads back the result, up to 200 rows. If Shopify rejects the query, Datae reads the error, fixes the query and runs it again rather than estimating the figures.

For plain revenue, order counts and best sellers, Datae uses its dedicated order tools instead, which apply your store's timezone and leave out cancelled and test orders. ShopifyQL is read-only, so a query never changes your store. If Shopify hasn't enabled report queries for Datae on your store, Datae says which figures it couldn't get.

  1. Install Datae. Shopify is connected from the start.
  2. Ask your question in the chat, such as one of the prompts below.
  3. Ask to see the query if you want to reuse it in Shopify's editor.

What can you ask Datae?

Install Datae, open the chat and paste one in. The answer comes from your own store's data.

  • “Which product landing pages had the most visits but the lowest conversion rate in the last 30 days?”
  • “What share of my customers have ordered more than once?”
  • “Which tracked variants have stock on hand but sold nothing in the last 90 days?”

Common questions

Is ShopifyQL the same as SQL?

No. It looks similar but has no SELECT, no joins and no subqueries. You query one schema at a time with FROM, list metrics with SHOW and split them with GROUP BY or TIMESERIES.

Can I use ShopifyQL on any Shopify plan?

Shopify's help center says modifying default reports and saving custom reports needs Advanced Shopify or Plus. Check Analytics, Reports in your own admin to see what your plan allows.

Can Datae change my store without asking?

Only if you turn on Autopilot. Datae installs read-only, and by default every change it prepares waits for you to approve it in Tasks. Switch on Autopilot in Settings and it makes the fixes it finds itself: safe fixes only (product SEO titles and descriptions, Klaviyo segments and draft campaigns), or everything within your limits (also discounts inside your margin floor, Pinterest Pins and social posts). Every change is listed in Tasks with the reason and undoes in a click for 30 days. Switch Autopilot off at any time.

Is my data secure?

Connections use OAuth and tokens are encrypted at rest. Datae fetches data on demand to answer each question rather than syncing your store. Chat transcripts, including the data tools returned, are kept so you can revisit past analyses; you can delete any chat at any time, and uninstalling removes all of your shop's data. Datae implements Shopify's mandatory privacy webhooks. See our Privacy Policy for the full picture.

Ask your store its first question

Free plan, no credit card. Datae installs read-only.

Install free on Shopify

More guides

Install free on Shopify