# How to put a calculation inside an IF formula in Excel

Write the calculation as the result IF returns: =IF(C2="Yes",B2*$G$1,0) charges tax only on taxable items.

**Excel:** `=IF(C2="Yes",B2*$G$1,0)` (Every current version)

**Google Sheets:** the same formula works.

## Example

Sample data (row 1 is the header):

| A | B | C | D | E | F | G |
| --- | --- | --- | --- | --- | --- | --- |
| Item | Price | Taxable | Tax |  | Tax rate | 0.0875 |
| Notebook | 4.99 | Yes |  |  |  |  |
| Apples | 3.49 | No |  |  |  |  |
| USB cable | 12.5 | Yes |  |  |  |  |
| Bread | 2.79 | No |  |  |  |  |
| Headphones | 59 | Yes |  |  |  |  |
| Milk | 3.29 | No |  |  |  |  |

Formula in D2, filled to D7: `=IF(C2="Yes",B2*$G$1,0)`

Result: $0.44; $0.00; $1.09; $0.00; $5.16; $0.00

## How it works

IF can return the result of any calculation, not only text. When `C2` is "Yes" it returns `B2*$G$1`; otherwise it returns 0. The rate is locked with $ so every row uses `G1`.

## Other ways

- `=B2*$G$1*(C2="Yes")`: In arithmetic TRUE counts as 1 and FALSE as 0, so the test can multiply the tax directly.
- `=IF(C2="Yes",ROUND(B2*$G$1,2),0)`: Rounds each line to cents, so the lines add up to the receipt total. (Rounded to whole cents: 0.44, 1.09 and 5.16.)

## Common mistakes

- Enter the rate as 8.75% or 0.0875. Typing 8.75 makes the tax bigger than the price.
- Leaving out the last argument returns FALSE for the non-taxable rows instead of 0.
- Typing the rate into the formula (`B2*0.0875`) means editing every row when it changes.

## Questions

**How do I get the price including tax?**

Add the tax to the price: `=B2+IF(C2="Yes",B2*$G$1,0)`.

**How do I total the tax without a helper column?**

Sum the taxable prices and apply the rate once: `=SUMIF(C2:C7,"Yes",B2:B7)*G1`.

Every formula and result on this page was checked by running it in the Spreadsheet Practice formula engine on 2026-10-30.

Source: https://spreadsheetpractice.com/formulas/calculation-inside-if
