When tax is included in the item price, Shopify’s report gives a slightly different number for gross sales than what can be calculated from LineItem(s). The reason is that the LineItem resource doesn’t return the discount before tax - and that’s a big problem, because trying to find this number with rounded down values will give a fair bit of discrepancy.
Now here’s the kicker, I can get the totalDiscountAmountBeforeTaxes
value from ProductSale and therefore calculate the exact same number that Shopify reports, but because it’s nested under Order → agreements → sales → totalDiscountAmountBeforeTaxes it’s too deep for bulk query. I don’t see any other way of getting to the ProductSales resource with bulk query, so I’m guessing it’s impossible?
Any pointers? Maybe I’m missing something?
Here’s some quick math to show what I mean:
Shopify orders report shows that Gross Sales for an order is $118.7. The OrderLine corresponding to that order/item returns the following from the API:
- originalUnitPriceSet: $130.57
- total tax: $8.90
- taxRate: 0.1
- allocated discount: $32.64
If you naively try to find the price before tax by doing $130.57 - $8.90 you get $121.67. But you’re supposed to get $118.70 - why? Well that’s because $8.90 does not include the tax portion that was removed by the discount.
If you try to calculate that number by doing: 130.57 - (8.90 + (32.64 * 0.1)) = $118.41
Close, but not perfect (0.25% diff).
If I use the totalDiscountAmountBeforeTaxes from sales, which is $29.67, I get:
130.57 - 32.64 + 29.67 - 8.90 = $118.70 <-Perfection! But, sadly, unachievable.
Unless I’m missing something there’s currently no way of getting an accurate gross sales number with a bulk query (when dynamic taxes and discounts are involved). Any chance Shopify can add totalDiscountAmountBeforeTaxes to LineItem or even better, originalUnitPriceSetBeforeTaxes? Please ?
Edit: Sample query and response
{
order(id: "gid://shopify/Order/11316826374516"){
id
createdAt
taxesIncluded
agreements(first: 100) {
nodes {
happenedAt
reason
id
sales(first: 100) {
nodes {
id
quantity
actionType
lineType
totalAmount {
shopMoney {
amount
}
}
totalDiscountAmountBeforeTaxes {
shopMoney {
amount
}
}
totalTaxAmount{
shopMoney{
amount
}
}
... on ProductSale {
lineItem{
id
}
}
}
}
}
}
lineItems(first: 100){
nodes {
id
quantity
discountAllocations{
allocatedAmountSet{
shopMoney{
amount
}
}
}
originalUnitPriceSet {
shopMoney {
amount
}
}
discountedUnitPriceAfterAllDiscountsSet{
shopMoney{
amount
}
}
taxLines{
rate
priceSet {
shopMoney{
amount
}
}
}
}
}
}
}
{
"data": {
"order": {
"id": "gid://shopify/Order/",
"createdAt": "2025-01-02",
"taxesIncluded": true,
"agreements": {
"nodes": [
{
"happenedAt": "2025-01-02",
"reason": "ORDER",
"id": "gid://shopify/SalesAgreement/",
"sales": {
"nodes": [
{
"id": "gid://shopify/Sale/",
"quantity": 1,
"actionType": "ORDER",
"lineType": "PRODUCT",
"totalAmount": {
"shopMoney": {
"amount": "97.93"
}
},
"totalDiscountAmountBeforeTaxes": {
"shopMoney": {
"amount": "29.67"
}
},
"totalTaxAmount": {
"shopMoney": {
"amount": "8.9"
}
},
"lineItem": {
"id": "gid://shopify/LineItem/"
}
},
{
"id": "gid://shopify/Sale/",
"quantity": null,
"actionType": "ORDER",
"lineType": "SHIPPING",
"totalAmount": {
"shopMoney": {
"amount": "6.19"
}
},
"totalDiscountAmountBeforeTaxes": {
"shopMoney": {
"amount": "0.0"
}
},
"totalTaxAmount": {
"shopMoney": {
"amount": "0.56"
}
}
}
]
}
}
]
},
"lineItems": {
"nodes": [
{
"id": "gid://shopify/LineItem/",
"quantity": 1,
"discountAllocations": [
{
"allocatedAmountSet": {
"shopMoney": {
"amount": "32.64"
}
}
}
],
"originalUnitPriceSet": {
"shopMoney": {
"amount": "130.57"
}
},
"discountedUnitPriceAfterAllDiscountsSet": {
"shopMoney": {
"amount": "97.93"
}
},
"taxLines": [
{
"rate": 0.1,
"priceSet": {
"shopMoney": {
"amount": "8.9"
}
}
}
]
}
]
}
}
}
}