Hi everyone,
I’m trying to calculate the previous day’s total gross sales in Shopify using the GraphQL orders query, aiming to match the totals from Shopify’s Total Sales report or the shopifyqlQuery results.
The shopifyqlQuery provides accurate results but only after a full 24-hour delay. When querying gross_sales and discounts for October 1st on the morning of October 2nd, it returns an incomplete figure that continues to update until midnight on October 3rd.
I need to calculate a near-final total using the GraphQL API’s fields like subtotalPriceSet, totalDiscountsSet, totalTaxSet, taxRate, billingCountry, etc. for each order. Despite testing formulas by region (e.g., handling tax-inclusive/exclusive pricing), I haven’t been able to replicate the report’s figures.
Example formula attempts:
- Sweden/Denmark (Tax-Inclusive): Gross Sales = (Subtotal Price - Total Discounts) / (1 + Tax Rate)> - UK (Tax-Exclusive):> > - When Tax Rate > 0: Gross Sales = (Subtotal Price - Total Discounts) / (1 - Tax Rate)> - When Tax Rate = 0: Gross Sales = Subtotal Price - Total Discounts> - Canada/Others: Gross Sales = Subtotal Price - Total Discounts
Has anyone successfully matched these totals in near real-time? Any advice would be appreciated!
Thanks for your help,
Guillaume
1 Like
Hi. I am also facing the same problem. I don’t know how to calculate the total revenue of a store through GraphQL. I just need to get the Total Price for a specified time period. Did you solve your problem?
1 Like
You will need to do the following this:
- Fetch a list (250 limit) of orders with your query params
- Get the nodes from the request to loop through and sum the data points
- Perform 1-2 recursively until you satisfy your query params (date range for example)
query GetOrders($query: String, $first: Int!, $after: String) {
orders(
first: $first
after: $after
query: $query
sortKey: CREATED_AT
reverse: true
) {
edges {
node {
id
name
processedAt
createdAt
totalPriceSet {
shopMoney {
amount
currencyCode
}
}
subtotalPriceSet {
shopMoney {
amount
}
}
totalShippingPriceSet {
shopMoney {
amount
}
}
totalTaxSet {
shopMoney {
amount
}
}
totalDiscountsSet {
shopMoney {
amount
}
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
Varaiables:
{
"first": 1,
"after": null | string,
"query": "(created_at:>='2025-01-22T06:00:00Z' AND created_at:<'2025-01-23T06:00:00Z')"
}
Take into consideration the timezones. I am -6 UCT but I had to adjust in the hours instead of using an actually offset.
Hope that help. Leave a like and accept if it helped!
Hopefully the answer works!