Calculate tax value from gross and tax percentage - percentage

I need to calculate the actual tax value when only the gross value and tax percentage is known.
The basic formula to calculate the gross amount:
Gross = Net * 1+Vat
Tax = Net * Vat
Example:
Net = 152.75 USD
Vat = 7 %
Gross = 152.75 * 1.07 = 163.44 USD
Tax = 152.75 * 0.07 = 10.69 USD
Proof:
Gross - Tax = Net
163.44 USD - 10.69 USD = 152.75 USD
However, in my case I only have Gross and Vat and need to get the Tax value in a single multiplication.
The current approach is the following:
Tax = Gross − (Gross / 1+Vat)
Example:
Tax = 163.44 USD - (163.44 USD / 1.07) = 10.69 USD
Question:
How can I get the Tax value with a simple multiplication, without the need of a subtraction.

The answer, posted in the comment by #PranavanSp:
Gross to Tax
Tax = Gross * Vat / (1 + Vat)
Example:
Tax = 163.44 * 0.07 / 1.07 = 10.69
Gross to Net
And for completeness, also the net calculation:
Net = Gross / (1 + Vat)
Example:
Net = 163.44 / 1.07 = 152.75

Related

CASE THEN will not allow = sign with a calculation

This is for a report that converts any items sold by grams to be converted to KG price. SSMS turns the = signs red in the WHEN andTHEN statement
CASE PRI.F30 /* This is the price */
WHEN sc.F263 ='4' /* 4 means priced by 100 grams */
THEN PRI.F30 = PRICE.F30 *10 /* price * 10 for KG price */
ELSE ''
END
Sample of red = signs
"Getting Incorrect Syntax" I could not find any examples of a calculation on the right side of the =. They all dealt with string replacements.

Integer Programming - If then statement

I am new to linear/integer programming and I am having a hard time formulating constraints for a specific if-then statement in a fixed charge problem. Suppose that there are five manufacturers of t-shirts, and a customer wishes to purchase 400 t-shirts while minimizing costs.
Producer
Variable cost/t-shirt
Delivery
Availability
A
3
40
200
B
3.5
30
100
C
4.10
Free delivery
100
D
4.1
30
200
E
3.2
30
First 100 t-shirts
E
2.90
20
101st-150th t-shirt
Producer E has an availability of 150 t-shirts. The first 100 t-shirts bought from producer E have a variable cost of $3.20 and a delivery fee of $30. If the customer orders more than 100 t-shirts from producer E, she can buy them at a variable cost of $2.90 and an additional fee of $20.
How can I create constraints from this if-then statement:
Xe1 = number of expensive t-shirts bought at producer E
Xe2 = number of cheap t-shirts bought at producer E
I want constraint Xe2 <= 0 to exist when Xe1 < 100.
Thanks in advance!
Since Xe1 and Xe2 are both non-negative integer variables, your constraint is the same as Xe1 <= 99 ⇒ Xe2 = 0. This can be formulated as follows:
b1 <= b2
99*b1 + 100*(1-b1) <= Xe1 <= 99*b1 + M*(1-b1)
1-b2 <= Xe2 <= M'*(1-b2)
where b1,b2 are binary helper variables and M and M' are upper bounds for Xe1 and Xe2, i.e. M = 101 and M' = 400.
This is a pretty standard "discount pricing model" where a discount price is awarded at a certain quantity. You can introduce 1 binary variable to the model to do this. This sounds like a H/W assignment.... :)
Let:
Xe1 be the qty bought from E at price 1
Xe2 be the qty bought from E at price 2
Ye be the decision to buy at the second price point y ∈ {0, 1}
Me2 be the qty available at the 2nd price (or a reasonable upper bound)
Then:
Xe2 <= Ye * Me2 # purchase at 2nd price point held to zero, unless Ye==1
Xe1 >= 100 * Ye # Ye can only be 1 if 100 are purchased at Xe1
There are some nuances here with the shipping. It isn't clear from the problem description if you bought 101 shirts from E if the shipping cost would be 30 + 20 (which would be odd) or the whole cost of shipping drops to 20. You could use the same indicator variable Ye to work something out for that as well.

Get (sum of sales) MINUS (sum of refund) to calculate profit in SQL oracle 11g

I am doing my database assignment, Airline Database.
So, I need to calculate profit for each flight.
Query 1 (Sum of payment_amount for each flight):
SELECT
f.flight_id
, SUM(r.payment_amount)
FROM
flight_schedule f
, reservation r
WHERE
r.flight_id = f.flight_id
GROUP BY
f.flight_id
ORDER BY
f.flight_id
;
Query 1 will return:
F0001 2000
F0002 2000
F0003 2000
F0004 2000
F0005 1000
Query 2 (Sum of refund_amount for each flight):
SELECT
f.flight_id
, SUM(e.refund_amount)
FROM
refund e
, flight_schedule f
, reservation r
WHERE
r.flight_id = f.flight_id
AND e.reservation_id = r.reservation_id
GROUP BY
f.flight_id
ORDER BY
f.flight_id
;
Query 2 will return:
F0001 50
F0002 50
F0003 50
F0004 50
F0005 100
So I want to get profit for each flight which is Query 1 that return payment_amount MINUS Query 2 that return refund_amount.
This is my expected output
F0001 1950
F0002 1950
F0003 1950
F0004 1950
F0005 900
I tried to used MINUS but I get error:
SP2-0042: unknown command "MINUS" - rest of line ignored.
I also tried to combine them:
SELECT
f.flight_id
, SUM(r.payment_amount) - SUM(e.refund_amount)
FROM
refund e
, flight_schedule f
, reservation r
WHERE
r.flight_id = f.flight_id
AND e.reservation_id = r.reservation_id
GROUP BY
f.flight_id
ORDER BY
f.flight_id
;
But I could not get the result I want
Here is my ERD:
The AND In your join, requires that a refund exist. the (+) says accept the data even if there is no refund match.
SELECT FLIGHT_ID, payX - payY
FROM
(
SELECT
f.flight_id
, SUM(r.payment_amount) payX, SUM(e.refund_amount) payY
FROM
refund e
, flight_schedule f
, reservation r
WHERE
r.flight_id = f.flight_id
AND e.reservation_id(+) = r.reservation_id
GROUP BY
f.flight_id
)
ORDER BY
flight_id
;

SQLite Compare Two Tables with Different Schema

I am working on a typical problem where I need to compare TWO tables with different schema for data differences.
Name: Table_A
Date Product Price Quantity
_______ __________ _______ ________
5/9/2016 1 103.2 15000
6/9/2016 2 80.15 13000
7/9/2016 3 14.50 50000
8/9/2016 3 15.50 35000
The Second Table is as follows:
Name: Table_B
TimeStamp Product Price Quantity
_________________ __________ _______ ________
20/9/2016 10:00am 1 106.00 20000
21/9/2016 10:10am 2 83.15 30000
25/9/2016 10:10am 2 83.15 50000
22/9/2016 10:30am 3 17.50 40000
23/9/2016 10:30am 3 19.50 60000
Let say Table B Product 3's price on 23/9/2016 is higher than Table A Product 3's price on 8/9/2016. What would be the SQL statement to compare the Price and Quantity in Ascending or Descending Order between two Tables?
I think we should use the INNER JOIN but I just got stuck. I have to sort out the dates from the Tables first and then able to pinpoint the Product in order to make a comparison on the Price.
I tried to write something like these but it is totally off course.
import sqlite3 as lite
import sys
con = lite.connect('Cable.db')
cur = con.cursor()
cur.execute("SELECT Product as product, Price FROM Table_A INNER JOIN "
"(SELECT Product as product, max(TimeStamp) as TimeStamp, Price
from Table_B WHERE TimeStamp ) ............)"
data = cur.fetchall()
counter = 0
for rows in data:
print(rows)
counter += 1
print(counter)
I just want to make the comparison works.
Thanks in advance.
Hank

SQLite Adding Previous Week Column to Current Week

I have the following data
Week Country Quantity Price
1 Sweden 2 $10
1 Germany 3 $20
2 Sweden 10 $20
What I would like to do is something like this:
Country Quantity Price Current Week Revenue Past Week Revenue
Sweden 30 100 300 3000 2000
If I was just doing Country, Quantity, Price, Current Week I'd use
SELECT Country, sum(uantity), sum(price), sum(price*quantity) as
revenue
from dataset where Week = 1 Group by Country.
However, I am at loss on how to add the previous week given that the where statement restricts the data to one week only?
Thanks!
Use conditional aggregation. That is, move the condition from the where to the sum() aggregation functions:
SELECT Country,
SUM(CASE WHEN Week = 1 THEN quantity END) as quantity_1,
SUM(CASE WHEN Week = 1 THEN price END) as price_1,
SUM(CASE WHEN Week = 1 THEN price*quantity END) as revenue_1,
SUM(CASE WHEN Week = 2 THEN quantity END) as quantity_2,
SUM(CASE WHEN Week = 2 THEN price END) as price_2,
SUM(CASE WHEN Week = 2 THEN price*quantity END) as revenue_2
FROM dataset d
WHERE Week IN (1, 2)
GROUP BY Country;
In the general case, use a correlated subquery to loop up the previous week's data:
SELECT Country,
SUM(Quantity * Price) AS Revenue,
(SELECT SUM(Quantity * Price)
FROM dataset AS PrevWeek
WHERE PrevWeek.Week = dataset.Week - 1
AND PrevWeek.Country = dataset.Country
) AS "Past Week Revenue"
FROM dataset
GROUP BY Country;

Resources