Skip to main content

Syntax

Syntax is the set of clauses and parameters you write. Every query needs FROM, which chooses a schema. A query must also select results with SHOW or VISUALIZE. Other clauses filter, group, and shape the result.

Use this reference to explore every clause and understand how to combine them into a query.

ShopifyQL

FROM sales
SHOW gross_sales
GROUP BY sales_channel WITH TOTALS
DURING last_month
ORDER BY gross_sales DESC
LIMIT 10
VISUALIZE gross_sales TYPE horizontal_bar

A query combines a schema, result selection, and optional clauses that shape the result. FROM with SHOW makes a complete tabular query. If you omit SHOW, then the query must include VISUALIZE to select the metric it renders.

ShopifyQL requires FROM, but doesn't require the main clauses to be written in a fixed order. Unlike in SQL, you set a date range with SINCE, UNTIL, or DURING instead of WHERE.

ShopifyQL

FROM sales
SHOW total_sales

FROM picks the schema you want to query, like sales or customers. Each schema lists the metrics and dimensions you can use, and querying a field outside that schema returns a parse error.

SHOW lists the metrics you want returned as result columns, like total_sales or orders. VISUALIZE also names a metric, and renders it as a chart.

Anchor to Grouping, filters, and timeGrouping, filters, and time

Group results by dimensions like sales_channel, product_title, or month with GROUP BY, bucket them over time with TIMESERIES, or filter on them with WHERE. The dimensions you group by come back alongside your metrics.

Time clauses are optional, but pairing TIMESERIES with a date window (SINCE, UNTIL, or DURING) scopes the results to that window. For example, TIMESERIES day SINCE -30d.

The ShopifyQL query FROM sales SHOW total_sales TIMESERIES day SINCE -30d. FROM is required, SHOW or VISUALIZE selects a result, and optional clauses like TIMESERIES and SINCE shape the result.

A query with optional clauses

FROM sales
SHOW total_sales
TIMESERIES day WITH TOTALS, PERCENT_CHANGE
SINCE startOfDay(-30d) UNTIL today
COMPARE TO previous_period
ORDER BY day ASC
VISUALIZE total_sales TYPE line

Every query is a sequence of clauses. Square brackets mark optional parts, a slash or | separates alternatives, and [, ...] marks a part you can repeat.

Some syntax isn't tied to a single clause. Combine metrics from related schemas in one query with a multi-fact query, or add comments to document a longer query.

FROM is required. A query also needs result selection from SHOW, VISUALIZE, or both, and you add only the other optional clauses your query needs.

ClauseRequired?What it does
FROMrequiredChooses the schema, which determines the available metrics and dimensions.
SHOWconditionalLists the metrics and dimensions to return from the schema. Required unless VISUALIZE selects a metric. Rename a field with AS.
WHEREoptionalFilters rows before grouping.
GROUP BYoptionalGroups results by one or more dimensions.
TIMESERIESoptionalBuckets results into a chartable time series.
WITHoptionalApplies modifiers like totals, percent change, and attribution.
HAVINGoptionalFilters grouped results.
SINCE, UNTIL, DURINGoptionalSets the reporting period.
COMPARE TOoptionalCompares the result against another period or target.
ORDER BYoptionalSorts results by one or more columns.
LIMIToptionalLimits the number of rows returned.
VISUALIZEconditionalRenders results as a chart and sets the type. Required when SHOW is omitted.
ANNOTATEoptionalOverlays contextual events on time-based charts.

Syntax

FROM schema[, ...]
[SHOW metric / dimension / expression[, ...]]
WHERE condition
GROUP BY dimension[, ...]
TIMESERIES time_dimension
WITH modifier[, ...]
HAVING condition
SINCE date_parameter [UNTIL date_parameter] | UNTIL date_parameter | DURING named_date_range
COMPARE TO comparison[, ...]
ORDER BY column [ASC | DESC][, ...]
LIMIT count [OFFSET count]
[VISUALIZE metric_or_alias [TYPE visualization_type][, ...] [MAX count] [ANNOTATE annotation]]

These terms are used throughout the ShopifyQL reference. Some keywords take metrics, some take dimensions, and some take either. If you're not sure whether a field is a metric or a dimension, check the schema reference for the schema named in FROM. Each schema lists its metrics and dimensions separately.

TermDefinition
KeywordA reserved word that begins a clause, such as FROM, SHOW, or GROUP BY.
ClauseA keyword and the parameters that follow it, such as SHOW total_sales. A query is a sequence of clauses.
ParameterA value you pass to a clause, such as a schema, column, condition, or date range.
OperatorA reserved word or symbol used within a condition, such as >=, STARTS WITH, or AND.
MetricA count or calculation that tracks a business indicator. Metrics are the columns you select with SHOW.
DimensionAn attribute you break metrics down by. Dimensions appear as columns, and their values define the rows.

Was this page helpful?