I’m trying to replicate the “Quantity ordered” metric from Shopify Analytics using the GraphQL Admin API.
In most cases, this seems to match the sum of quantities from Sales Agreements where:
However, I’ve encountered some cases where quantities from:
also appear to be included in the Shopify Analytics value.
This makes it unclear what the exact underlying logic is.
QUESTION: Under what conditions are ORDER_EDIT agreement quantities included or excluded? Is there a recommended way to reliably reproduce this metric?
1 Like
Hey @Keanna_Driedger
I don’t have visibility into your specific order data, but I ran a test on my end covering all three scenarios: original order, order edit, and refund. I created an order with 1 item, added 2 more via an order edit, then refunded 1 unit. The agreements query returned reason: ORDER with quantity: 1, reason: ORDER_EDIT with quantity: 2, and reason: REFUND with quantity: -1, all on lineType: PRODUCT.
Looking at the screenshot you shared, “Quantity ordered” explicitly excludes reversed quantity, which means the right approach is to sum sale.quantity for lineType: PRODUCT while filtering to only ORDER and ORDER_EDIT reasons. Leaving REFUND out keeps the metric focused on ordering demand before returns impact the data, which matches the description in your screenshot.
One other option you could look at is the shopifyqlQuery. This lets you query the analytics data directly from the API, which sidesteps the need to reconstruct this logic from agreements altogether.
Hi @KyleG-Shopify
In my own testing, the behaviour hasn’t been consistent enough for me to conclude that ORDER_EDIT quantities should always be included in the Shopify Analytics Quantity ordered metric.
I tested two edited orders:
In both cases, the Shopify Analytics Quantity ordered value for the associated sale_ids was 0.
Because we’re trying to match this metric accurately in our app, I’m trying to understand the exact inclusion logic for edits. Specifically:
At the moment, my test results suggest that summing sale.quantity for lineType = PRODUCT and reason IN (ORDER, ORDER_EDIT) does not always reproduce the native metric.
Any additional detail on how Shopify Analytics determines whether an edit is counted would be really helpful.
Hey @Keanna_Driedger that testing is really helpful.
Looking closer in to the sales discrepancies documentation it addresses what you’re seeing: “Ordered quantity only includes products that were specifically ordered by the customer and doesn’t include anything that was added to their order by editing the order.” So the zeroes on those edit-related sale_ids are expected in this case. Filtering to only reason: ORDER and excluding both ORDER_EDIT and REFUND should get you closest to what Analytics reports.
For context, the analytics data points reference has the full breakdown of how each metric is calculated. Also, the order editing considerations doc notes that if an order is edited after the day it was placed, the edit shows up as a separate order in reports. That could be contributing to the confusing discrepancies you see when you’re comparing line-by-line.
Hey @Keanna_Driedger are you still experiencing this issue, or can I mark this as solved?
Hi @KyleG-Shopify ,
I’m still experimenting with this and trying to reconcile the behaviour.
From your last message, I understand that the closest approximation is to use:
However, that seems to conflict with your earlier example, where an ORDER_EDIT also contributed to the Quantity ordered value. I have not been able to reproduce this in my test store, but have also seen this in client stores.
Could you clarify in what cases does an ORDER_EDIT agreement contribute to Quantity ordered?
@Keanna_Driedger when order edit is contributing, do you see the edit on a different day than the original order? My thought was that this discrepency could be what you are seeing https://help.shopify.com/en/manual/fulfillment/managing-orders/editing-orders/considerations#order-edit-analytics
If you edit an order after the day the order was placed, then the edit displays as a separate order in your reports. Reports display an edited order as a new order, even though a new order hasn’t been created.
Hi @Keanna_Driedger
Are you still seeing this issue?
@KyleG-Shopify In my original test cases, the edits were made on a different date than the original sale, but the Quantity ordered value was still 0 for those edit-related sale IDs.
I’m having trouble consistently reproducing cases where an edit contributes to Quantity ordered, even though I can see that it does happen in some client stores.
I ran a few additional tests:
Test 1 (same-day edit):
-
Original order: 1 item with quantity = 2 → Quantity ordered = 2
-
Edit: reduced quantity by 1 → Quantity ordered = 0
-
Edit: added a new item with quantity = 1 → Quantity ordered = 1
Test 2 (edit on a different order - order placed on different date):
-
I added an additional item via an edit
-
In this case, the added item did not result in any value for Quantity ordered
Have you been able to find any additional resources more clearly explaining the definition of quantity ordered?
Hey @Keanna_Driedger
Before we go deeper down the Sales Agreements path, I want to circle back to something from my earlier reply. Have you had a chance to try shopifyqlQuery? If your app needs to match Analytics exactly, that’s the most reliable path.
If shopifyqlQuery doesn’t fit your use case, I think we should take a step back from trying to replicate this specific Analytics metric and instead focusing on the business logic your app actually needs. To help me understand, what’s the specific question your app’s end users need answered? ie. Something like “how many units were ordered today” vs. “how many units are we fulfilling” vs. “net sales volume after edits and returns”
Can you also share the specific analytics report you are using to replicate the quantity ordered?
This way instead of trying to unpack the difference you are seeing in the report vs API, we can narrow down the correct API to query (and possible look in to if the report you are using is the best for the task).
Hi @KyleG-Shopify ,
Thanks for the suggestion. We haven’t explored shopifyqlQuery, as we’re trying to avoid adding support for a separate API purely to replicate this metric.
Our goal is to ensure that reports in our app align closely with what merchants see in Shopify Analytics, since considered our source of truth. Ideally, we’d like to replicate the same logic using the Admin API so the numbers match without requiring a different query method.
From what I understand, Quantity ordered represents the total units ordered, excluding refunds. Where I’m running into difficulty is around how order edits are handled. In practice, edits don’t seem to be treated consistently, and I haven’t been able to identify a clear rule for when ORDER_EDIT quantities are included versus excluded.
I don’t have a single fixed report to point to, as this has come up across a range of custom reports we’ve worked through, but the inconsistency is making it difficult to confidently reproduce the metric.