Spreadsheet Practice

How to put a calculation inside an IF formula in Excel

Formula (Excel and Google Sheets)

=IF(C2="Yes",B2*$G$1,0)

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

Result on the example
one result per row in D2, filled down to D7
Works in
Every current version
Google Sheets
Same formula

See it work

The formula is already in D2, filled down to D7. Change any input and the result updates, or edit the formula to experiment.

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.

=IF(C2="Yes",B2*$G$1,0)

Result0.436625

  1. C2"Yes"

    The value in C2.

  2. C2="Yes"TRUE

    The = operator tests whether the two sides are equal.

  3. B2$4.99

    The value in B2.

  4. $G$18.75%

    The value in G1.

  5. B2*$G$10.436625

    The * operator multiplies.

  6. IF(C2="Yes",B2*$G$1,0)0.436625

    IF: Returns one value if a test is true, another if false.

    • logical_testC2="Yes"TRUE
    • value_if_trueB2*$G$10.436625
    • value_if_false0not used

In Google Sheets

The same formula works in Google Sheets: =IF(C2="Yes",B2*$G$1,0). We ran it in Google Sheets mode on the same data and it returns the same results.

Other ways to do it

Each one was run on the same example sheet.

FormulaResultWhen to use it
=B2*$G$1*(C2="Yes")$0.44, $0.00, $1.09…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)$0.44, $0.00, $1.09…Different resultRounds 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.

Try it yourself

Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.

Put a calculation inside an IF formula

In D2, calculate the tax at the rate in G1 for taxable items, and 0 for the rest. Fill down to D7.

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.

Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.