• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Excel IF Formulas and What Not To Do

You are here: Home / Excel Formulas / Excel IF Formulas and What Not To Do
excel nested if functions what not to do
September 22, 2022 by Mynda Treacy

We can learn a lot from looking at what others do in Excel, both the good and the not so good. Last week one of my course members asked me to help them understand what a nested IF formula was doing in a file they’d inherited in their new job. It contained 15 nested IF functions, 5 CEILING functions and a load of repetition. The person who wrote this formula must have had one hell of a headache when they finished concocting it. Here it is:

=CEILING(IF(C11="consignment ",(IF($G11>30,(CEILING(IF($B11="Station A",IF($F11>10,($B$4-$D11+$F11),($B$4-$D11)),IF($F11>10,($B$5-$D11+$F11),($B$5-$D11))),10)+(H11-AGO/365*30*IntRate)),(CEILING(IF($B11="Station A",IF($F11>10,($B$4-$D11+$F11),($B$4-$D11)),IF($F11>10,($B$5-$D11+$F11),($B$5-$D11))),10)))+20),(IF($G11>30,(CEILING(IF($B11="Station A",IF($F11>10,($B$4-$D11+$F11),($B$4-$D11)),IF($F11>10,($B$5-$D11+$F11),($B$5-$D11))),10)+(H11-AGO/365*30*IntRate)),(CEILING(IF($B11="Station A",IF($F11>10,($B$4-$D11+$F11),($B$4-$D11)),IF($F11>10,($B$5-$D11+$F11),($B$5-$D11))),10))))),10)/FXRate

And here is the data on a sheet called 'Formula' (anonymised for confidentiality):

nested if mistakes 1

I re-wrote the formula and didn’t use any IFs! Not only is my formula way shorter, but it’s also much easier to decipher.

In this tutorial I’m going to:

  • Step through the process I take to decipher complex formulas like this
  • We’ll look at the avoidable mistakes they made writing the formula
  • I’ll show you how to write a simpler formula that doesn’t contain any IFs!

Watch the Video

Subscribe YouTube

Download Workbook

Enter your email address below to download the sample workbook.

By submitting your email address you agree that we can email you our Excel newsletter.
Please enter a valid email address.

Download the Excel Workbook and follow along. Note: This is a .xlsx file please ensure your browser doesn't change the file extension on download.



Deciphering Formulas

The first thing I did was copy the formula out of one of the cells and create it as a formula in the Advanced Formula Environment add-in (see video for more), which automatically adds line breaks and colour coding, making the formula easier to read:

nested if mistakes 2

Note: if you aren’t able to download the add-in, you can add your own line breaks inside the formula bar using ALT+ENTER.

I could see the first IF formula criteria contained an extra space on the end of 'consignment ', which I corrected. You could also easily see there was a lot of repetition which I’ve enclosed in colour coded boxes below:

nested if mistakes 3

The CEILING function rounds numbers up to the nearest multiple of significance. In this formula it is rounding up to the nearest 10. Notice it is rounding twice, once at the IF level and again before converting with the foreign exchange rate. Given how this formula has been written and because this is a pricing model, as opposed to a scientific calculation, I put this down to user error as I doubt the intention is to round it up twice.

Below you can see that removing the internal CEILING functions reduces the noise a little. It results in a very small difference of 0.00262 or 0.15% for the first customer, which I expect is acceptable given the objective of this formula.

nested if mistakes 4

Format as Table

The next change I made was to convert the data to an Excel Table so that I could see the structured references rather than plain cell references, which instantly makes the formula readable in English:

nested if mistakes 5

Tip: To convert the cell references to the Table’s structured references, edit the formula and double click the cell references and then select the cell again in the table. Repeat for all references! Alternatively, you can use Find & Replace to replace the cell references in the formula with the Structured References, but I personally find it just as quick to replace them with the mouse.

Extract Criteria

Lastly, I isolated the various criteria so I could see the logic being applied. Here is the spreadsheet again so we can easily reference it:

nested if mistakes 1

There are 3 logical tests applicable to all scenarios:

  1. If the Nature of Delivery in column C = consignment, add 20
  2. If the Transport Rate in column F > 10, add the Transport Rate amount from column F
  3. If the Credit Days in column G > 30, add the Provision for Financial Charges (col H), minus the Land Cost (in cell G5 named AGO)/365*30*Interest Rate in cell E4

These conditions apply to all customers therefore there’s no need to repeat them in multiple IFs. Instead, we can simply add them on at the end. More on that in a moment.

Repeating IFs

The last repeating IFs detect which Reference Station is in column B. If it’s Station A, the value in cell B4 is used, and if it’s Station B, the value in cell B5 is used. Otherwise, the formula is the same:

nested if mistakes 6

The author of this formula has used nested IFs to cycle through the different calculations for each station. A more efficient way is to use a lookup formula to find the value for the Reference Station and then add the other charges based on the logic identified earlier.

Lastly, the formula is wrapped in CEILING to round it up to a multiple of 10 and then divided by the Foreign Exchange Rate in cell E5, called FXRate:

nested if mistakes 7

Simplified Formula with NO IFs

Like I said earlier, an easier and more efficient way to write this formula is to use a lookup function to find the value for the station. Then we can add the other charges based on the criteria, apply the rounding with CEILING and convert the currency.

In the formula below you’ll notice that I haven’t used IF at all:

=CEILING(
   XLOOKUP([@[Reference station ]],$A$4:$A$5,$B$4:$B$5,,0)
   -[@[Applicable discount ]]
   +([@[Nature of Delivery]]="Consignment")*20
   +([@[Transport Rate ]]>10)*[@[Transport Rate ]]
   +([@[Credit days]]>30)* ([@[Provision for Financial Charges ]]- AGO/365*30*IntRate)
,10)
/FXRate

Note: if you don’t have XLOOKUP, you can use VLOOKUP or INDEX & MATCH instead.

The arguments in blue are Boolean logical tests, if the test is TRUE, it returns the numeric equivalent of 1, which is then multiplied by the respective values/calculations. If the test returns FALSE, it returns 0 and 0 multiplied by anything is 0.

Taking the first logical test as an example: ([@[Nature of Delivery]]="Consignment")*20

In English it reads: if the nature of delivery is ‘Consignment’, the logical test returns 1, multiplied by 20 = 20

I could have written these as IFs, but it’s not necessary. For example, the above line could be written:

IF(([@[Nature of Delivery]]="Consignment", 20, 0)

In English the whole formula reads:

1) Lookup the reference station in cells A4:A5 and return the cost in column B.

2) Take off the value in the Applicable Discount column.

3) Plus, if the Nature of Delivery is consignment, add 20.

4) Plus, if the Transport Rate is greater than 10, add the Transport Rate amount.

5) Plus, if the Credit Days are greater than 30, take the value in the Provision for Financial Charges column, minus the AGO amount, divided by 365, times by 30, times by the Interest Rate.

6) Round up the value so far to the nearest 10

7) And finally, divide the final amount by the Foreign Exchange Rate.

Lessons Learned

1. While some functions can perform the same calculations that others can, it doesn’t mean they’re the best ones to use. It’s important to know a range of functions so you can choose the correct function for the task. Check out my Advanced Formulas course here.

2. Structure your formula with carriage returns so they’re easier to read.

3. Format your data in an Excel Table so you can use the structured references, which makes formulas readable in English.

4. You don’t always need IF to apply a logical test.

excel nested if functions what not to do

More Excel Formulas Posts

excel formulas

Excel Formulas

Here you'll find a list of common Microsoft Excel formulas and functions explained in plain English, and applied to real life examples.
if or and if and formulas

Excel IF AND OR Functions Explained

Excel IF AND OR Functions are a great team. In this tutorial I show you some practical examples of IF AND and IF OR formulas.
IFERROR Function

Excel’s IFERROR Puts an End to Messy Workarounds

Excel's new function; IFERROR will improve the speed of your formulas and reduce workbook file sizes. I don't know how we lived without it.
sumif and sumifs formulas

Excel SUMIF and SUMIFS Formulas Explained

How to write Excel SUMIF and SUMIFS function, including examples and download workbook.

More Excel Formulas Posts

ai-aided excel formula editor

AI Aided Excel Formula Editor

Save time with this free AI Excel formula editor add-in that writes, edits, improves and interprets formulas for you!
top excel functions for data analysts

Top Excel Functions for Data Analysts

Must know Excel Functions for Data Analysts and what functions you don’t have to waste time learning and why.
excel advanced formula environment

Excel Advanced Formula Environment

Excel Advanced Formula Environment is a long awaited, new improved way to write, name and store Excel formulas.
Pro Excel Formula Writing Tips

Pro Excel Formula Writing Tips

Must know Excel formula writing tips, tricks and tools to make you an Excel formula ninja, including a new formula editor.
excel shaping arrays

New Array Shaping Excel Functions

The Excel Shaping Array Functions makes it easier than ever to reshape arrays and ranges using these purpose built functions
excel nested if functions what not to do

Excel IF Formulas and What Not To Do

Excel IF formulas can get out of hand when you nest too many IFs. Not only do they become unwieldy they’re difficult for anyone to understand
excel image function

Excel IMAGE Function

The Excel IMAGE Function enables you to embed images in a cell using a formula. It supports BMP, JPG/JPEG, GIF, TIFF, PNG, ICO, and WEBP files

Excel VSTACK and HSTACK Functions

New Excel VSTACK and HSTACK functions makes combining arrays of cells easy and with some clever tricks we can extend their capabilities.
identify overlapping dates and times in excel

Identify overlapping dates and times in Excel

How to identify overlapping dates and times in Excel with a formula that checks a range of cells. Works with Dates and Times.
New Excel Text Functions

TEXTSPLIT, TEXTBEFORE and TEXTAFTER Functions

TEXTAFTER, TEXTBEFORE and TEXTSPLIT are exciting new Excel Text functions. They’re fairly self-explanatory, however TEXTSPLIT has some cool features.


Category: Excel FormulasTag: excel formulas
Previous Post:excel image functionExcel IMAGE Function
Next Post:Custom Excel Dashboard Backgroundsexcel dashboards custom backgrounds

Reader Interactions

Comments

  1. ramesh rathod

    September 22, 2022 at 10:30 pm

    Thnaks

    Reply
    • Mynda Treacy

      September 23, 2022 at 8:53 am

      My pleasure, Ramesh!

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Current ye@r *

Leave this field empty

Sidebar

More results...

Featured Content

  • 10 Common Excel Mistakes to Avoid
  • Top Excel Functions for Data Analysts
  • Secrets to Building Excel Dashboards in Less Than 15 Minutes
  • Pro Excel Formula Writing Tips
  • Hidden Excel Double-Click Shortcuts
  • Top 10 Intermediate Excel Functions
  • 5 Pro Excel Dashboard Design Tips
  • 5 Excel SUM Function Tricks
  • 239 Excel Keyboard Shortcuts

100 Excel Tips and Tricks eBook

Download Free Tips & Tricks

Subscribe to Our Newsletter

Receive weekly tutorials on Excel, Power Query, Power Pivot, Power BI and More.

We respect your email privacy

Guides and Resources

  • Excel Keyboard Shortcuts
  • Excel Functions
  • Excel Formulas
  • Excel Custom Number Formatting
  • ALT Codes
  • Pivot Tables
  • VLOOKUP
  • VBA
  • Excel Userforms
  • Free Downloads

239 Excel Keyboard Shortcuts

Download Free PDF

Free Webinars

Excel Dashboards Webinar

Watch our free webinars and learn to create Interactive Dashboard Reports in Excel or Power BI

Click Here to Watch Now

mynda treacy microsoft mvpHi, I'm Mynda Treacy and I run MOTH with my husband, Phil. Through our blog, webinars, YouTube channel and courses we hope we can help you learn Excel, Power Pivot and DAX, Power Query, Power BI, and Excel Dashboards.

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk – For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.