Calculate Total Gross Sales from GraphQL API

Topic summary

Problem: Users are trying to calculate accurate gross sales totals from Shopify’s GraphQL API to match official reports, but struggle with timing delays and formula accuracy.

Key Challenge:

  • Shopify’s shopifyqlQuery provides accurate gross sales data but only after a 24-hour delay
  • GraphQL API fields (subtotalPriceSet, totalDiscountsSet, totalTaxSet) don’t directly replicate report totals
  • Tax handling varies by region (tax-inclusive vs. tax-exclusive pricing)

Attempted Solutions:

  • Region-specific formulas tested for Sweden/Denmark (tax-inclusive), UK (tax-exclusive), and Canada
  • Formulas adjust for tax rates but still don’t match official figures

Proposed Workaround:
One user suggests:

  1. Fetch orders in batches (250 limit) using GraphQL with date range filters
  2. Loop through results and sum relevant price fields
  3. Recursively paginate until all orders are processed
  4. Account for timezone differences in query parameters

A code snippet demonstrates querying orders with totalPriceSet, subtotalPriceSet, shipping, tax, and discount fields.

Status: No confirmed solution for matching official gross sales calculations in near real-time.

Summarized with AI on November 2. AI used: claude-sonnet-4-5-20250929.

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:

  1. Fetch a list (250 limit) of orders with your query params
  2. Get the nodes from the request to loop through and sum the data points
  3. 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!