Using SHOPLINE QL to Customize Analytics Reports
SHOPLINE QL is an analytics query language that helps you build more flexible custom reports in SHOPLINE. With SHOPLINE QL, you can choose the metrics you want to analyze, filter report data, group results by dimensions, and create custom metrics with simple calculations.
This guide introduces common SHOPLINE QL terms, basic query structure, frequently used clauses, query examples, and important usage notes.
Understanding Common SHOPLINE QL Terms
Before using the examples in this guide, you may find it helpful to understand these common SHOPLINE QL terms:
| Term | Description |
| Dataset | The data source queried by SHOPLINE QL. For example, sales refers to sales-related data. |
| Metric | A measurable value, such as sales amount, order count, or net sales. |
| Dimension | A field used to group or segment report data, such as date, product, or location. |
| Clause | A fixed part of a SHOPLINE QL query, such as FROM, VIEW, FILTER, or LIMIT. |
| Alias | A display name assigned with AS for a field or calculated custom field, making it easier to identify in the report. |
| Time range | The date or time period covered by the query. You can set it with DURING or SINCE / UNTIL. |
| Compare range | A comparison period generated with COMPARE, such as the previous period or the same period last year. |
| Totals | Summary results generated with EXTEND TOTALS. |
Understanding the Structure of a SHOPLINE QL
A SHOPLINE QL query is made up of clauses. Each clause tells SHOPLINE what data to query, which fields to show, how to filter or group the results, and which time range to use.
When creating a custom report with SHOPLINE QL, each query should include:
-
FROM: Specifies the dataset. -
VIEW: Specifies the fields, metrics, or calculated values to display. - A time range: Uses
DURING, or usesSINCE/UNTILto specify a date range.
A typical SHOPLINE QL query may look like this:
FROM sales
VIEW total_sales, order_cnt
FILTER payment_status IN ('Payment successful', 'Unpaid')
GROUP BY day
DURING last_30_day
COMPARE previous_period
EXTEND TOTALS
ORDER BY total_sales DESC
LIMIT 20
The table below summarizes the available SHOPLINE QL clauses and their purposes. Click a clause name to navigate to its dedicated section for more details and examples.
Clause |
Description |
FROM |
Specifies the dataset to query. For example, sales refers to sales-related data. |
VIEW |
Specifies the metrics, fields, or calculated values to display in the report. |
FILTER |
Filters the data so the report only includes matching records. |
POSTFILTER |
Filters the results after metrics are calculated. For example, it can show only grouped results where sales are above a specific amount. |
GROUP BY |
Groups data by dimension, such as date, product, or location. |
DURING |
Uses a preset time range, such as today, the last 30 days, or this month. |
SINCE / UNTIL |
Uses a specific start time and end time. |
COMPARE |
Compares the selected time range with the previous period or the same period last year. |
EXTEND TOTALS |
Adds summary totals to the report results. |
ORDER BY |
Sorts the results. Currently, each query supports sorting by one field. |
LIMIT |
Limits the number of rows returned by the query. |
OFFSET |
Skips a specified number of rows. This is usually used with LIMIT. |
| Note: Use uppercase clauses and place each clause on a separate line. This makes your query easier to read, review, and maintain. |
Configuring SHOPLINE QL in Custom Reports
You can enter and run SHOPLINE QL when creating or editing a custom report. Use the SHOPLINE QL editor to write your query, then run it to preview the report results before saving.
To configure SHOPLINE QL in a custom report:
- From your SHOPLINE admin, go to Analytics > Reports.
- Click Create custom report to create a new report, or open an existing custom report to edit it.
- Enter a report name. Report names must be unique. If the name already exists, the system will ask you to rename it.
- Select a dataset from the drop-down list. Currently, newly created custom reports only support Sales data.
- Click Next, then in the report editor, enter your SHOPLINE QL query in the SHOPLINE QL editor.
- Click Run to preview the report results.
- Review the preview. If the result looks correct, save the report.
Note: If the query cannot be parsed or the preview does not return the expected result, check that the query includes FROM, VIEW, and a time range, and that all field names, punctuation, and quotation marks are entered correctly. |
Using SHOPLINE QL Clauses in Queries
The following sections explain the most commonly used SHOPLINE QL clauses, including their purpose, syntax, and usage examples.
FROM and VIEW
FROM specifies the dataset you want to query. VIEW specifies the fields, metrics, or calculated values you want to display in the report.
For example, to view today’s sales:
FROM sales
VIEW total_sales
DURING todayYou can also display multiple metrics in the same report:
FROM sales
VIEW total_sales, net_sales, order_cnt
DURING last_7_dayTo create a new metric based on existing metrics, use arithmetic operators in VIEW, then use AS to name the new metric.
For example, to calculate average order value:
FROM sales
VIEW (net_sales / order_cnt) AS average_order_value
DURING last_monthFor example, to calculate adjusted sales based on gross sales and discounts:
FROM sales
VIEW (gross_sales - discounts) AS adjusted_sales
DURING last_monthSHOPLINE QL supports the following arithmetic operators:
| Operator | Description |
* |
Multiplication |
/ |
Division |
+ |
Addition |
- |
Subtraction |
When a calculated field contains multiple operators, multiplication and division are calculated before addition and subtraction. You can also use parentheses to control the calculation order.
For example, to calculate adjusted sales first, then divide the result by order count:
FROM sales
VIEW ((gross_sales - discounts) / order_cnt) AS average_adjusted_sales
DURING last_month
Note: When using a calculated field, use AS to name the new field. Field names in the same report must be unique. |
FILTER
FILTER narrows the data before metrics are calculated. You can use it to include only records that match specific statuses, products, locations, or other conditions.
For example, to view only sales with successful payments:
FROM sales
VIEW total_sales
FILTER payment_status IN ('Payment successful')
DURING todayFor example, to view sales for products with names that contain shirt:
FROM sales
VIEW total_sales, order_cnt
FILTER product_spu_name CONTAINS ('shirt')
DURING last_30_dayFILTER supports the following comparison operators:
| Operator | Description |
= |
Equal to |
!= |
Not equal to |
<> |
Not equal to |
> |
Greater than |
< |
Less than |
>= |
Greater than or equal to |
<= |
Less than or equal to |
For example, to include only records where sales are greater than 100:
FROM sales
VIEW total_sales
FILTER total_sales > 100
DURING last_30_dayYou can also use AND, OR, and NOT to combine multiple filter conditions, or use IN, NOT IN, CONTAINS, and NOT CONTAINS to match specific values.
For example, to include successful payments and exclude selected customer types:
FROM sales
VIEW total_sales
FILTER (payment_status IN ('Payment successful')) AND NOT buyer_type IN ('New customer', 'Returning customer')
DURING todayFor example, to exclude orders with specific order statuses:
FROM sales
VIEW total_sales
FILTER order_status NOT IN ('Completed', 'Shipped')
DURING today
Note: String values must use single quotation marks, such as 'shirt' or 'Payment successful'. The query may fail if you use Chinese quotation marks or another quotation mark format. |
POSTFILTER
POSTFILTER filters the results after metrics are calculated. This is useful when you want to group the data first, then keep only the grouped results that meet certain conditions.
For example, to view sales by state/province over the last 30 days and show only locations where sales are greater than 1000:
FROM sales
VIEW total_sales
GROUP BY province
DURING last_30_day
POSTFILTER total_sales > 1000FILTER and POSTFILTER are applied at different stages. FILTER filters the original data before metrics are calculated. POSTFILTER filters the calculated results after the metrics are generated.
For example, if you want to calculate sales for each state/province first, then show only locations where sales reach a specific amount, use POSTFILTER.
GROUP BY
GROUP BY groups report data by dimension. Without GROUP BY, the report usually returns a summary result. After you add GROUP BY, the report breaks down results by the dimensions you specify.
For example, to view sales by day over the last 30 days:
FROM sales
VIEW total_sales
GROUP BY day
DURING last_30_dayFor example, to view sales by state/province and city over the last 30 days:
FROM sales
VIEW total_sales
GROUP BY province, city
DURING last_30_dayCommon time dimensions include:
| Dimension | Description |
hour |
Groups data by hour. |
day |
Groups data by day. |
week |
Groups data by week. |
month |
Groups data by month. |
quarter |
Groups data by quarter. |
year |
Groups data by year. |
hour_of_day |
Groups data by hour of the day. |
day_of_week |
Groups data by day of the week. |
week_of_year |
Groups data by week of the year. |
month_of_year |
Groups data by month of the year. |
DURING, SINCE, and UNTIL
Each SHOPLINE QL query should include a time range. Use DURING to select a preset time range, or use SINCE and UNTIL to specify exact dates.
To use a preset time range:
FROM sales
VIEW total_sales
DURING last_30_dayTo use a specific date range:
FROM sales
VIEW total_sales
SINCE '2026-05-01' UNTIL '2026-05-31'To specify both date and time:
FROM sales
VIEW total_sales
SINCE '2026-05-01 00:00:00' UNTIL '2026-05-31 23:59:59'Common DURING time ranges include:
| Range | Description |
today |
Today. |
yesterday |
Yesterday. |
last_24_hour |
The last 24 complete hours. |
last_7_day |
The last 7 days, excluding today. |
last_30_day |
The last 30 days, excluding today. |
last_90_day |
The last 90 days, excluding today. |
this_week |
This week. |
this_month |
This month. |
last_month |
Last month. |
this_quarter |
This quarter. |
last_quarter |
Last quarter. |
this_year |
This year. |
last_year |
Last year. |
Note: Use SINCE and UNTIL for specific dates. Use DURING only with supported preset time ranges. |
COMPARE
COMPARE compares the selected time range with another time range.
For example, to compare data from the last 30 days with the previous period:
FROM sales
VIEW total_sales
GROUP BY day
DURING last_30_day
COMPARE previous_periodCurrently supported comparison types include:
| Compare type | Description |
previous_period |
Compares the selected range with the previous period of the same length. |
previous_year |
Compares the selected range with the same period last year. |
EXTEND TOTALS
EXTEND TOTALS adds summary totals to the report results. This is useful when you group data by location, product, or another dimension and also want to see the overall total.
For example, to view sales by state/province over the last 30 days and include summary totals:
FROM sales
VIEW total_sales, order_cnt
GROUP BY province
DURING last_30_day
EXTEND TOTALS
Note: Currently, EXTEND supports TOTALS. The query may fail if you use an unsupported format. |
ORDER BY, LIMIT, and OFFSET
ORDER BY sorts the results. LIMIT controls the number of rows returned by the query. OFFSET skips a specified number of rows and is usually used with LIMIT.
For example, to view the top 10 products by sales over the last 30 days:
FROM sales
VIEW total_sales, order_cnt
GROUP BY product_spu_name
DURING last_30_day
ORDER BY total_sales DESC
LIMIT 10ASC sorts results from low to high. DESC sorts results from high to low.
To skip the first 40 rows and view the next 20 rows:
FROM sales
VIEW total_sales
GROUP BY product_spu_name
DURING last_30_day
ORDER BY total_sales DESC
LIMIT 20
OFFSET 40
Note: Currently, each query supports sorting by one field. The field used in ORDER BY must already appear in VIEW or GROUP BY. |
Common SHOPLINE QL Examples
The following examples can help you start building custom reports. You can adjust the metrics, dimensions, filters, or time ranges based on your reporting needs.
View Top Products by Sales Over the Last 30 Days
FROM sales
VIEW total_sales, order_cnt
GROUP BY product_spu_name
DURING last_30_day
ORDER BY total_sales DESC
LIMIT 10
View Daily Sales Trends and Compare with the Previous Period
FROM sales
VIEW total_sales, net_sales
GROUP BY day
DURING last_30_day
COMPARE previous_period
ORDER BY day ASC
LIMIT 30
Filter Sales Data by Product Name
FROM sales
VIEW total_sales, order_cnt
FILTER product_spu_name CONTAINS ('shirt')
GROUP BY product_spu_name
DURING last_7_day
ORDER BY total_sales DESC
LIMIT 20
View This Month’s Sales Summary by State/Province
FROM sales
VIEW total_sales, order_cnt
GROUP BY province
DURING this_month
EXTEND TOTALS
ORDER BY total_sales DESC
LIMIT 50
Filter Calculated Results by State/Province
FROM sales
VIEW total_sales
GROUP BY province
DURING last_30_day
POSTFILTER total_sales > 1000
View Sales Data for a Specific Date Range
FROM sales
VIEW total_sales
FILTER payment_status IN ('success', 'failed')
SINCE '2026-05-01 00:00:00' UNTIL '2026-05-20 23:59:59'
Important Notes for Using SHOPLINE QL
Before creating a custom report with SHOPLINE QL, keep these rules in mind:
Before creating a custom report with SHOPLINE QL, keep these rules in mind:
- Each query should include
FROM,VIEW, and one time range. - Use uppercase clauses and place each clause on a separate line.
- String values must use single quotation marks.
- When using calculated fields, use
ASto name the field. - Field names in the same report must be unique.
- Currently, calculated fields in
VIEWsupport addition, subtraction, multiplication, and division. Function calls are not supported. - Currently, each
ORDER BYclause supports sorting by one field. - Fields used in
ORDER BYmust already appear inVIEWorGROUP BY. - If
LIMITis not set, the system returns up to2000rows by default. - In non-export scenarios,
LIMITshould not exceed2000. - Currently,
EXTENDsupportsTOTALS. - Currently,
COMPAREsupportsprevious_periodandprevious_year. - Use
DURINGwith supported preset time ranges. UseSINCEandUNTILfor specific dates. - Keep query time ranges under 3 years.
- Start with a simple query first. After confirming that the results are correct, you can gradually add filters, grouping, comparisons, or calculated fields.
Q: Will SHOPLINE QL change my store data?
No. SHOPLINE QL is only used to query and display analytics report data. It does not change your orders, products, customers, or sales records.
Q: When should I use SHOPLINE QL?
Use SHOPLINE QL when you need more flexibility in your report setup. For example, you can customize metric definitions, combine multiple filter conditions, or group sales data by specific dimensions.
Q: Can I use SHOPLINE QL to define a new metric?
Yes. You can calculate a new metric based on existing metrics by using addition, subtraction, multiplication, or division, then name the new metric with AS. For example, you can divide net sales by order count to calculate average order value.
Q: Why did my SHOPLINE QL query fail?
Common causes include incorrect field names, missing time ranges, unnamed calculated fields, duplicate field names, or unsupported syntax. Check that FROM, VIEW, and the time range are complete first, then confirm that the field names and punctuation are correct.
Q: Can I use SHOPLINE QL to view data from a specific date range?
Yes. Use SINCE and UNTIL to specify a start time and end time. For example, you can view data from May 1, 2026 to May 31, 2026.
Q: Is there a limit on the number of rows returned in a report?
Yes. Use LIMIT to control the number of rows returned by the query. If LIMIT is not set, the system returns the default number of rows.
To keep the report page loading smoothly, some charts or tables may limit the number of rows displayed on the page. If the preview does not show all results, export the report data to view more complete data.