# Why is tax calculation inconsistent in invoice creation?

Shopify Partner
3 0 1

Hello Shopify Community,

I am currently building a tool for creating invoices & invoice-reminders.

I ran into a peculiar issue with the tax calculations.

From my understanding this is the workflow:

For each LineItem

• Calculate LinePrice (currentQuantity * discountedUnitPrice - discountApplications[only when targetSelection != ALL])
• Add LinePrice * LineTaxRate to TotalTaxes

then add Shipping costs to TotalPrice and ShippingCost-Taxes to TotalTaxes

then remove all Discounts with targetSelection = ALL from both the total and the taxes

and then we can go ahead and calculate the Tax.

So far so good. I have this example wich really confused me:

4 Products:

• 1x 108,40 € -discounted to-> 54,20€
• 2x 49,58 € -discounted to-> 24,79€
• 1x 15,97 € -discounted to-> 7,99€

in Total: 111,77€

Then an order-wide discount of 20,-€ -> 91,77€

German 19% Tax Rate results in 17,4363€ (then tax = floor(tax*100)/100) ??) => 17,43

this flooring resulted in correct results for most orders but this one got it compleatly wrong.

Shopify says the correct amount of Taxes would be 17.45 ?!?

This is very confusing since not even rounding would result in this value.

I ended up using the order->currentTotalTaxSet but I really want to understand what is causing this inconsistency behind the scenes - or what I am doing wrong.

Hope somebody can help me figure this one out,

best regards ~ Marco

Replies 3 (3)
Shopify Partner
40 1 9

Hello @Marco_Dittrich ,

Let's have a breakdown to understand more:

• LineItems:

1x 108.40€ -discounted to-> 54.20€
2x 49.58€ -discounted to-> 24.79€
1x 15.97€ -discounted to-> 7.99€

• Total Price calculation:

LinePrice = (1 * 54.20€) + (2 * 24.79€) + (1 * 7.99€) = 111.77€

Order-wide discount:
Total Price after discount = 111.77€ - 20€ = 91.77€

• Tax calculation:

German 19% Tax Rate

Total Taxes without rounding:
Total Taxes = (111.77€ * 0.19) = 21.2573€

• Rounding:

To comply with rounding rules, you mentioned using floor(tax*100)/100. Applying this rounding method:

Total Taxes rounded = floor(21.2573 * 100) / 100 = 21.25€

Shopify's reported value:
According to your information, Shopify reports the tax amount as 17.45€.

Discrepancy:
There seems to be a discrepancy between the tax amount you calculated (17.43€) and the value reported by Shopify (17.45€). This could be due to differences in rounding methods or tax calculation logic between your custom tool and Shopify's system.

To investigate the inconsistency further and gain a better understanding, I recommend reaching out to Shopify Support, providing them with the specific details of your example, and asking for clarification on their tax calculation methods and rounding practices. They can offer insights into their system's implementation and help you understand the differences observed in the tax calculations.

Hope this can help.

Jen from TrueProfit

TrueProfit - The Ultimate Real-time Profit Tracker For Shopify

Get in touch with us: App Store | Website | Youtube | FAQ
Shopify Partner
3 0 1

Hello Jen,

thank you for taking your time to understand this issue.

I have already contacted the Shopify Plus supportteam but they pointed me to this forum.

The calculation you have provided does not include the order-wide discount of 20,-€ the tax is calculated afterwards as far as I know. Then we arrive at 91.77 * 0.19 not 111.77 * 0.19 wich is 1.37ct lower that what shopify provides as ground truth.

Visitor
2 0 1

Hello Marco,

Did you have any luck finding out this issue?
I have the same problem with many of my invoices, but not always.
I have a bookkeeper making me crazy saying everything is wrong....

Kind regards Marloes