• 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
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

When to say No to Excel Nested IFs

You are here: Home / Excel Formulas / When to say No to Excel Nested IFs
October 7, 2016 by Mynda Treacy

In Excel 2007, Microsoft thought it would be a good idea to increase the number of times you can nest IF functions from 7 to 64.

S I X T Y – F O U R! Are you kidding me? If you need to nest any more than 7 IFs then you should be using VLOOKUP or INDEX & MATCH.

Every now and again I see a serial IF nester. Sometimes they don’t only nest IFs, they also nest other functions as well.

Just take this 22 IF whopper as an example:

=IF(AND([@[Code]]="No Discount",[@[New_Rate]]=""),[@[Code]],
IF(AND([@[Code]]="No Discount",LEFT([@[New_Rate]],7)="Group"), "Group",
IF(AND([@[Code]]="No Discount",LEFT([@[New_Rate]],8)="Group"), "Budget",
IF(AND([@[Code]]="No Discount",LEFT([@[New_Rate]],3)="TLZ"), "Travel ",
IF(AND([@[Code]]="No Discount",LEFT([@[New_Rate]],2)="TZ"), "Travel ",
IF(AND([@[Code]]="No Discount",LEFT([@[New_Rate]],2)="AL"), "Amazon",
IF(AND([@[Code]]="No Discount",LEFT([@[New_Rate]],3)="ALW"), "Amazon",
IF(AND([@[Code]]="No Discount",LEFT([@[New_Rate]],3)="AMA"), "Amazon",
IF(AND([@[Code]]="No Discount",LEFT([@[New_Rate]],2)="LZ"), "Lazy",
IF(AND([@[Code]]="No Discount",LEFT([@[New_Rate]],3)="C2C"), "Coast",
IF(AND([@[Code]]="No Discount",LEFT([@[New_Rate]],3)="RCG"), "RCG",
IF(AND([@[Code]]="No Discount",LEFT([@[New_Rate]],3)="ALP"), "Amazon",
IF(AND([@[Code]]="No Discount",LEFT([@[New_Rate]],4)="ALLC"), "Amazon",
IF([@[Code]]="No Discount",
IF(ISNUMBER(MATCH([@[New_Rate]], Clean!$N:$N,0)),[@[Code]],[@[New_Rate]]),
IF(LEFT([@[Code]],2)="TT","TT",
IF(LEFT([@[Code]],2)="TB","TT",
IF(LEFT([@[Code]],3)="ETW","TT",
IF(LEFT([@[Code]],2)="ET","TT",
IF(LEFT([@[Code]],3)="RCG","RCG",
IF(LEFT([@[Code]],8)="RogerCox","RCG",
IF(LEFT([@[Code]],2)="GS","Great South",
IFERROR(VLOOKUP([@[Code]], Clean!F:G,2,FALSE),[@[Code]]))))))))))))))))))))))

No, I didn’t make this up. This is a real formula sent to me by one of our members. I’ve changed the references for privacy, but otherwise it’s the real deal.

The Problem with too many Nested IFs

Aside from the fact that a formula like this is very difficult to read and understand for anyone inheriting the workbook, let alone the person who wrote it, the main problem you’re likely to encounter are performance issues.

If the first IF function evaluates to TRUE, then it’s ok. Excel stops at that point and returns the result and the remaining 21 IFs don’t get evaluated.

However, the cells where every one of the IF functions evaluates to FALSE consume a huge amount of processing power.

Just think about the work Excel has to go through to get to that last IF.

To be clear, it has to evaluate:

  • 22 IF functions
  • 13 AND functions
  • 19 LEFT functions
  • 1 ISNUMBER
  • 1 MATCH
  • 1 IFERROR
  • 1 VLOOKUP

And that’s just in one cell. Now multiply that by a hundred, or a thousand, or tens of thousands of cells.

And it doesn’t even have to be the last IF that’s the problem. Any more than 2 nested IFs in large workbooks can be a problem.

So, if you’re wondering why your workbooks are large and slow, then take a look at your nested formulas.

Alternatives to Excel Nested IFs

The alternative to nested IF functions is often a simple VLOOKUP formula.

To recap, the syntax for VLOOKUP is:

VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])

Let’s start off with a simpler nested IF example:

excel nested IFs example

This formula uses IF to return the State for each city (I’ve wrapped each IF onto a separate row for clarity):

=IF([@City]="Sydney","NSW",
IF([@City]="Melbourne","VIC",
IF([@City]="Adelaide","SA",
IF([@City]="Brisbane","QLD",
IF([@City]="Darwin","NT",
IF([@City]="Perth","WA"))))))

A more efficient way to return the State values is to use VLOOKUP to find the city (lookup_value) in the table_array and return the state:

return State values using VLOOKUP

Tip: For bonus efficiency points sort the city column in alphabetical order. Then you can use the VLOOKUP sorted list method i.e. use 1 or TRUE for the last VLOOKUP argument; [range_lookup]:

=VLOOKUP([@City],TableArray,2,1)

Caution: with the range_lookup argument set to 1 or TRUE you must ensure every value you want to lookup is in the table_array, because this VLOOKUP will not return an error if your lookup_value isn’t found. Instead it will return the next closest match.

An even better alternative to VLOOKUP is INDEX & MATCH. If your workbook is still slow, then replace VLOOKUP’s with INDEX & MATCH. Make sure the MATCH value is in a helper column i.e. not another nested formula.

Download the 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. Note: this is a .xlsx file please ensure your browser doesn't change the file extension on download.

Alternatives to Multiple Nested Functions

The 22 IF whopper formula sent in by one of our members needs more than just a VLOOKUP to replace it. Unfortunately, I don’t have the data so I can’t demonstrate a solution, however I can describe the approach.

Simply put, the formula needs to be broken into separate steps:

Step 1: Insert a helper column to extract the lookup_value for each row. That is, put the AND and LEFT parts of the formula into a helper column, so you can then use VLOOKUP to find that value in the lookup table_array.

Now, I know some of you pride yourselves on not needing helper columns, but using helper columns doesn’t make you a formula amateur.

In fact, often it’s much more efficient to use a helper column than to write formulas like the one above.

Step 2: create a lookup_table that contains the lookup_values and the result you want returned. Remember, use INDEX & MATCH if VLOOKUP is still slow.

More Performance Tips

If you’re often wrangling sluggish Excel workbooks then it will pay to spend some time perusing fellow Excel MVP, Charles Williams’ website.

Charles has also developed a toolset designed to help you understand, manage and improve workbook performance. It’s called Fast Excel and includes:

Profiler - gives you a comprehensive set of tools focussed on finding and prioritising calculation bottlenecks. If your spreadsheet takes more than a few seconds to calculate you need FastExcel profiler to find out and prioritize the reasons for the slow calculation

Manager - contains tools to help you build, debug and maintain Excel workbooks.

Speed Tools - provides you with a state-of-the-art tool-kit to help you speed up your Excel Calculations

If you have performance tips please take a moment to share them in the comments below.

More Excel Formulas Posts

excel formula by example

Excel Formula by Example

Excel can now write a formula by example. Simply give it an example or two of the result and Excel will write the formula.
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.


Category: Excel Formulas
Previous Post:Excel Styles
Next Post:Excel Expression Definition

Reader Interactions

Comments

  1. David Murphy

    October 7, 2016 at 10:50 pm

    Good post and it highlights that, quite often, Excel can become more than a handful to a) maintain and b) understand.

    An alternative solution, of course, would be to write a custom function – although I do appreciate that not all users may want to dive into a bit of VBA. But the advantage with the VBA/Custom Function is that you can build a much more readable “formula” due to the structured approach of VBA and have as much complexity as you want without cluttering up your worksheet.

    Reply
    • Mynda Treacy

      October 8, 2016 at 8:23 am

      Thanks, David.

      UDF’s are an option but they often perform worse than the built in functions. Plus, like you say, you need to know how to write VBA 🙂

      Reply
  2. Peter Buyze

    October 7, 2016 at 10:06 pm

    Just as an aside, but not quite: the reason one would prefer INDEX & MATCH to VLOOKUP is because the latter can only return data to the right of the reference column. But that statement is not quite right

    Reply
    • Mynda Treacy

      October 8, 2016 at 8:21 am

      Yep, I posted a tutorial on using CHOOSE with VLOOKUP 5 years ago ;-p

      https://www.myonlinetraininghub.com/excel-choose-function

      Still, I’d recommend INDEX & MATCH over VLOOKUP and CHOOSE.

      Reply
      • Sunny Kow

        October 8, 2016 at 12:14 pm

        Having taught Excel to 100’s of my colleagues, somehow VLOOKUP is overwhelmingly their favorite choice (possibly 99%). My guess is they prefer using one formula instead of two and speed is not a concern to them. I too prefer VLOOKUP and rarely need INDEX & MATCH in my work. Writing a UDF would be my last choice.

        Reply
        • Mynda Treacy

          October 8, 2016 at 9:09 pm

          VLOOKUP is my all time favourite function 🙂

          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

239 Excel Keyboard Shortcuts

Download Free PDF

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.