I have something like:
Price Quantity Tax (%)
2.2 34 8
1.3 29 7
And so on...
After that I get something like:
Subtotal: 112.6 (Sumation: Price x Quantity)
Discount: 23 (This is a percentage, it changes)
Tax (percentage): ?
What's the proper formula to calculate the "Average Tax" if I apply a variable discount?
let:
$S = subtotal$
$D = $discount percentage
$T = $tax percentage
$F =$ total after adjustment
$$F = (S - S*D)*(1.0+T)$$
$$F = S*(1.0 - D)*(1.0+T)$$
You are taking off a percentage first for the discount so that's where the $1-D$ comes from.
When you pay 8% tax on something your subtotal is actually multiplied by 1.08.
The "Average Tax" would be the total tax paid over many purchases divided by the total subtotal.