0% found this document useful (0 votes)
14 views

If Function

Uploaded by

Riaz Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

If Function

Uploaded by

Riaz Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

‭IF function‬

‭ he‬ ‭IF‬ ‭function‬ ‭is‬ ‭one‬ ‭of‬ ‭the‬ ‭most‬ ‭popular‬ ‭functions‬ ‭in‬ ‭Excel,‬ ‭and‬ ‭it‬ ‭allows‬ ‭you‬ ‭to‬
T
‭make logical comparisons between a value and what you expect.‬

‭ o‬ ‭an‬ ‭IF‬ ‭statement‬ ‭can‬ ‭have‬ ‭two‬ ‭results.‬ ‭The‬ ‭first‬ ‭result‬ ‭is‬ ‭if‬ ‭your‬ ‭comparison‬ ‭is‬
S
‭True, the second if your comparison is False.‬

‭ or‬‭example,‬‭=IF(C2=”Yes”,1,2)‬‭says‬‭IF(C2‬‭=‬‭Yes,‬‭then‬‭return‬‭a‬‭1,‬‭otherwise‬‭return‬‭a‬
F
‭2).‬

‭Example 1‬

‭■‬ ‭=IF(C2=”Yes”,1,2)‬

I‭n‬‭the‬‭above‬‭example,‬‭cell‬‭D2‬‭says:‬‭IF(C2‬‭=‬‭Yes,‬‭then‬‭return‬‭a‬‭1,‬‭otherwise‬‭return‬‭a‬
‭2)‬

‭■‬ ‭=IF(C2=1,”Yes”,”No”)‬

I‭n‬ ‭this‬ ‭example,‬ ‭the‬ ‭formula‬ ‭in‬ ‭cell‬ ‭D2‬ ‭says:‬ ‭IF(C2‬ ‭=‬ ‭1,‬‭then‬‭return‬‭Yes,‬‭otherwise‬
‭return‬‭No)‬‭As‬‭you‬‭see,‬‭the‬‭IF‬‭function‬‭can‬‭be‬‭used‬‭to‬‭evaluate‬‭both‬‭text‬‭and‬‭values.‬‭It‬
‭can‬‭also‬‭be‬‭used‬‭to‬‭evaluate‬‭errors‬‭.‬‭You‬‭are‬‭not‬‭limited‬‭to‬‭only‬‭checking‬‭if‬‭one‬‭thing‬
‭is‬ ‭equal‬ ‭to‬ ‭another‬ ‭and‬ ‭returning‬ ‭a‬ ‭single‬ ‭result,‬ ‭you‬ ‭can‬ ‭also‬ ‭use‬ ‭mathematical‬
‭operators‬ ‭and‬ ‭perform‬ ‭additional‬ ‭calculations‬ ‭depending‬ ‭on‬ ‭your‬ ‭criteria.‬ ‭You‬ ‭can‬
‭also nest multiple IF functions together in order to perform multiple comparisons.‬
‭Example 2‬

‭■‬ ‭=IF(C2>B2,”Over Budget”,”Within Budget”)‬

I‭n‬‭the‬‭above‬‭example,‬‭the‬‭IF‬‭function‬‭in‬‭D2‬‭is‬‭saying‬‭IF(C2‬‭Is‬‭Greater‬‭Than‬‭B2,‬‭then‬
‭return “Over Budget”, otherwise return “Within Budget”)‬

‭■‬ ‭=IF(C2>B2,C2-B2,0)‬

I‭n‬ ‭the‬ ‭above‬ ‭illustration,‬ ‭instead‬ ‭of‬ ‭returning‬ ‭a‬ ‭text‬ ‭result,‬ ‭we‬ ‭are‬‭going‬‭to‬‭return‬‭a‬
‭mathematical‬ ‭calculation.‬ ‭So‬ ‭the‬ ‭formula‬ ‭in‬ ‭E2‬ ‭is‬ ‭saying‬ ‭IF(Actual‬ ‭is‬ ‭Greater‬ ‭than‬
‭Budgeted,‬ ‭then‬ ‭Subtract‬ ‭the‬ ‭Budgeted‬ ‭amount‬ ‭from‬ ‭the‬ ‭Actual‬ ‭amount,‬ ‭otherwise‬
‭return nothing).‬
‭Example 3‬

‭■‬ ‭=IF(E7=”Yes”,F5*0.0825,0)‬

I‭n‬ ‭this‬ ‭example,‬ ‭the‬ ‭formula‬ ‭in‬ ‭F7‬ ‭is‬ ‭saying‬ ‭IF(E7‬ ‭=‬ ‭“Yes”,‬‭then‬‭calculate‬‭the‬‭Total‬
‭Amount in F5 * 8.25%, otherwise no Sales Tax is due so return 0)‬

‭ ote:‬‭If‬‭you‬‭are‬‭going‬‭to‬‭use‬‭text‬‭in‬‭formulas,‬‭you‬‭need‬‭to‬‭wrap‬‭the‬‭text‬‭in‬‭quotes‬‭(e.g.‬‭“Text”).‬
N
‭The only exception to that is using TRUE or FALSE, which Excel automatically understands.‬

‭Common problems‬
‭Problem‬ ‭What went wrong‬

‭ ‬‭(zero)‬‭in‬
0 ‭ here‬ ‭was‬ ‭no‬‭argument‬‭for‬‭either‬‭value_if_true‬‭or‬‭value_if_False‬
T
‭cell‬ ‭arguments.‬‭To‬‭see‬‭the‬‭right‬‭value‬‭returned,‬‭add‬‭argument‬‭text‬‭to‬‭the‬
‭two arguments, or add TRUE or FALSE to the argument.‬

‭ NAME?‬
# ‭This usually means that the formula is misspelled.‬
‭in cell‬
‭IF function – nested formulas and avoiding pitfalls‬
‭ he‬‭IF‬‭function‬‭allows‬‭you‬‭to‬‭make‬‭a‬‭logical‬‭comparison‬‭between‬‭a‬‭value‬‭and‬‭what‬
T
‭you expect by testing for a condition and returning a result if True or False.‬

‭■‬ ‭=IF(Something is True, then do something, otherwise do something else)‬

‭ o‬ ‭an‬ ‭IF‬ ‭statement‬ ‭can‬ ‭have‬ ‭two‬ ‭results.‬ ‭The‬ ‭first‬ ‭result‬ ‭is‬ ‭if‬ ‭your‬ ‭comparison‬ ‭is‬
S
‭True, the second if your comparison is False.‬

I‭F‬‭statements‬‭are‬‭incredibly‬‭robust,‬‭and‬‭form‬‭the‬‭basis‬‭of‬‭many‬‭spreadsheet‬‭models,‬
‭but‬ ‭they‬ ‭are‬ ‭also‬ ‭the‬ ‭root‬ ‭cause‬ ‭of‬ ‭many‬ ‭spreadsheet‬ ‭issues.‬ ‭Ideally,‬ ‭an‬ ‭IF‬
‭statement‬‭should‬‭apply‬‭to‬‭minimal‬‭conditions,‬‭such‬‭as‬‭Male/Female,‬‭Yes/No/Maybe,‬
‭to‬ ‭name‬‭a‬‭few,‬‭but‬‭sometimes‬‭you‬‭might‬‭need‬‭to‬‭evaluate‬‭more‬‭complex‬‭scenarios‬
‭that require nesting* more than 3 IF functions together.‬

‭* “Nesting” refers to the practice of joining multiple functions together in one formula.‬

‭Technical details‬

‭ hile‬ ‭Excel‬ ‭will‬ ‭allow‬ ‭you‬ ‭to‬ ‭nest‬ ‭up‬ ‭to‬ ‭64‬ ‭different‬ ‭IF‬ ‭functions,‬ ‭it’s‬ ‭not‬ ‭at‬ ‭all‬
W
‭advisable to do so. Why?‬

‭■‬ M
‭ ultiple IF statements require a great deal of thought to build correctly‬
‭and make sure that their logic can calculate correctly through each‬
‭condition all the way to the end. If you don’t nest your formula 100%‬
‭accurately, then it might work 75% of the time, but return unexpected‬
‭results 25% of the time. Unfortunately, the odds of you catching the 25%‬
‭are slim.‬

‭■‬ M
‭ ultiple IF statements can become incredibly difficult to maintain,‬
‭especially when you come back some time later and try to figure out what‬
‭you, or worse someone else, was trying to do.‬

I‭f‬‭you‬‭find‬‭yourself‬‭with‬‭an‬‭IF‬‭statement‬‭that‬‭just‬‭seems‬‭to‬‭keep‬‭growing‬‭with‬‭no‬‭end‬
‭in sight, it’s time to put down the mouse and rethink your strategy.‬

‭ et’s‬ ‭look‬ ‭at‬ ‭how‬ ‭to‬ ‭properly‬ ‭create‬ ‭a‬ ‭complex‬ ‭nested‬ ‭IF‬ ‭statement‬ ‭using‬ ‭multiple‬
L
‭IFs, and when to recognize that it’s time to use another tool in your Excel arsenal.‬

‭Examples‬
‭ ollowing‬ ‭is‬ ‭an‬ ‭example‬ ‭of‬ ‭a‬ ‭relatively‬ ‭standard‬ ‭nested‬ ‭IF‬ ‭statement‬ ‭to‬ ‭convert‬
F
‭student test scores to their letter grade equivalent.‬
‭■‬ =
‭ IF(D2>89,"A",IF(D2>79,"B",IF(D2>69,"C",IF(D2>59,"D","F"))))‬
‭This complex nested IF statement follows a straightforward logic:‬

‭1.‬ ‭If the Test Score (in cell D2) is greater than 89, then the student gets an A‬

‭2.‬ ‭If the Test Score is greater than 79, then the student gets a B‬

‭3.‬ ‭If the Test Score is greater than 69, then the student gets a C‬

‭4.‬ ‭If the Test Score is greater than 59, then the student gets a D‬

‭5.‬ ‭Otherwise the student gets an F‬

‭ his‬ ‭particular‬ ‭example‬ ‭is‬ ‭relatively‬ ‭safe‬ ‭because‬ ‭it’s‬ ‭not‬ ‭likely‬ ‭that‬ ‭the‬ ‭correlation‬
T
‭between‬ ‭test‬ ‭scores‬ ‭and‬ ‭letter‬ ‭grades‬ ‭will‬ ‭change,‬ ‭so‬ ‭it‬ ‭won’t‬ ‭require‬ ‭much‬
‭maintenance.‬ ‭But‬ ‭here’s‬ ‭a‬ ‭thought‬ ‭–‬ ‭what‬ ‭if‬ ‭you‬ ‭need‬ ‭to‬ ‭segment‬ ‭the‬ ‭grades‬
‭between‬ ‭A+,‬ ‭A‬ ‭and‬ ‭A-‬‭(and‬‭so‬‭on)?‬‭Now‬‭your‬‭four‬‭condition‬‭IF‬‭statement‬‭needs‬‭to‬
‭be rewritten to have 12 conditions! Here’s what your formula would look like now:‬

‭■‬ =
‭ IF(B2>97,"A+",IF(B2>93,"A",IF(B2>89,"A-",IF(B2>87,"B+",IF(B2>83,"B",‬
‭IF(B2>79,"B-",‬
‭IF(B2>77,"C+",IF(B2>73,"C",IF(B2>69,"C-",IF(B2>57,"D+",IF(B2>53,"D",I‬
‭F(B2>49,"D-","F"))))))))))))‬

I‭t’s‬ ‭still‬ ‭functionally‬ ‭accurate‬ ‭and‬ ‭will‬ ‭work‬ ‭as‬ ‭expected,‬ ‭but‬ ‭it‬ ‭takes‬ ‭a‬ ‭long‬ ‭time‬ ‭to‬
‭write‬‭and‬‭longer‬‭to‬‭test‬‭to‬‭make‬‭sure‬‭it‬‭does‬‭what‬‭you‬‭want.‬‭Another‬‭glaring‬‭issue‬‭is‬
‭that‬ ‭you’ve‬ ‭had‬ ‭to‬ ‭enter‬ ‭the‬‭scores‬‭and‬‭equivalent‬‭letter‬‭grades‬‭by‬‭hand.‬‭What‬‭are‬
‭the‬‭odds‬‭that‬‭you’ll‬‭accidentally‬‭have‬‭a‬‭typo?‬‭Now‬‭imagine‬‭trying‬‭to‬‭do‬‭this‬‭64‬‭times‬
‭with‬ ‭more‬ ‭complex‬ ‭conditions!‬ ‭Sure,‬ ‭it’s‬ ‭possible,‬ ‭but‬‭do‬‭you‬‭really‬‭want‬‭to‬‭subject‬
‭yourself to this kind of effort and probable errors that will be really hard to spot?‬

‭ ip:‬ ‭Every‬ ‭function‬ ‭in‬ ‭Excel‬ ‭requires‬ ‭an‬ ‭opening‬ ‭and‬ ‭closing‬ ‭parenthesis‬ ‭().‬ ‭Excel‬
T
‭will‬ ‭try‬ ‭to‬ ‭help‬ ‭you‬ ‭figure‬ ‭out‬ ‭what‬ ‭goes‬ ‭where‬ ‭by‬ ‭coloring‬ ‭different‬ ‭parts‬ ‭of‬ ‭your‬
f‭ormula‬‭when‬‭you’re‬‭editing‬‭it.‬‭For‬‭instance,‬‭if‬‭you‬‭were‬‭to‬‭edit‬‭the‬‭above‬‭formula,‬‭as‬
‭you‬ ‭move‬ ‭the‬ ‭cursor‬ ‭past‬ ‭each‬ ‭of‬ ‭the‬ ‭ending‬ ‭parentheses‬ ‭“)”,‬ ‭its‬ ‭corresponding‬
‭opening‬ ‭parenthesis‬ ‭will‬ ‭turn‬ ‭the‬ ‭same‬ ‭color.‬ ‭This‬ ‭can‬ ‭be‬ ‭especially‬ ‭useful‬ ‭in‬
‭complex‬ ‭nested‬ ‭formulas‬ ‭when‬ ‭you’re‬ ‭trying‬ ‭to‬ ‭figure‬ ‭out‬ ‭if‬ ‭you‬ ‭have‬ ‭enough‬
‭matching parentheses.‬

‭Youtube Detailed Video:‬‭https://youtu.be/KkTaQ5OjAGc?feature=shared‬

You might also like