Alternatives to Nested If Function

andsoitis1 pts0 comments

7 ALTERNATIVES TO NESTED IF FUNCTION | by Crispo Mwangi | MediumSitemapOpen in appSign up<br>Sign in

Medium Logo

Get app<br>Write

Search

Sign up<br>Sign in

7 ALTERNATIVES TO NESTED IF FUNCTION

Crispo Mwangi

5 min read·<br>Jun 24, 2017

Listen

Share

IF function is one of the most used functions in Excel.<br>In my opinion, it is the foundation of all programming and Excel’s formula mastery. However, it is also one of the most misused functions, especially Nested IF.<br>Especially now with Excel 2007 and beyond, you can nest up to 64 IF functions to form complex, slow and hard-to-understand IF THEN ELSE statement.<br>You don’t need to slow or complicate your worksheet anymore, here are the 7 faster alternatives:<br>VLOOKUP<br>CHOOSE & MATCH<br>REPT<br>INDEX & MATCH<br>SUMPRODUCT<br>BOOLEAN LOGIC<br>SUMIF<br>VLOOKUP<br>Say you have below price list with mixed currency and you want to convert them to USD

The first step would be to look up the exchange rate per currency. Most users would use below nested IF function<br>=IF(B2=$F$3,$G$3,IF(B2=$F$4,$G$4,IF(B2=$F$5,$G$5,IF(B2=$F$6,$G$6,IF(B2=$F$7,$G$7,IF(B2=$F$8,$G$8))))))This is not only hard to understand but will definitely slow down your worksheet.<br>Below VLOOKUP Function is the 1st Alternative.

=VLOOKUP(B2,$F$2:$G$8,2,FALSE)How it works<br>VLOOKUP uses the exact match criteria to retrieve the exchange rates in Column 2 of the exchange rate table ($F$2:$G$8).<br>Note: You MUST specify the match criteria for VLOOKUP to exactly retrieve correct rates. IF the criteria is omitted, VLOOKUP, by default, does an approximate search giving wrong results.<br>CHOOSE & MATCH FUNCTIONS

=CHOOSE(MATCH(B2,$F$3:$F$8,0),$G$3,$G$4,$G$5,$G$6,$G$7,$G$8)How it works<br>MATCH(B2,$F$3:$F$8,0)=6MATCH function searches for the currency in the exchange rate table and returns its relative position.<br>CHOOSE function returns the exchange rate based on its position in the list. MATCH function above provides this position.<br>=CHOOSE(6,$G$3,$G$4,$G$5,$G$6,$G$7,$G$8) = 1.25REPT FUNCTION

=REPT($G$3,B2=$F$3)&REPT($G$4,B2=$F$4)&REPT($G$5,B2=$F$5)<br>&REPT($G$6,B2=$F$6)&REPT($G$7,B2=$F$7)&REPT($G$8,B2=$F$8)How It Works<br>REPT Function returns a specific text string a specified number of times. If the specified number is zero, REPT returns an empty string.<br>Excel recognizes internally the value of TRUE as number 1 and value of FALSE as 0. This is a fact that REPT utilizes to determine the number of times to repeat.<br>Also, note that in our function above ONLY 1 test will evaluate TRUE, others return FALSE.<br>=REPT($G$3,FALSE)&REPT($G$4,FALSE)&REPT($G$5,FALSE)<br>&REPT($G$6,FALSE)&REPT($G$7,FALSE)&REPT($G$8,TRUE)Where the test evaluates to FALSE, REPT functions returns an empty string (” “)<br>=""&""&""<br>&""&""&"1.25435"INDEX & MATCH

{=INDEX($G$3:$G$8,MATCH(TRUE,($F$3:$F$8=B2),0))}How it works<br>MATCH function checks if the currency exists in the range ($F$3:$F$8=B2). If TRUE, it returns the relative position of the currency.<br>INDEX function returns the exchange rate in the range ($G$3:$G$8) given its position. MATCH provides this relative position.<br>NB: This is an array formula, Therefore, Ctrl+Shift+Enter<br>If want to avoid array formula, use a combination of INDEX, MATCH, INDEX shown below<br>=INDEX($G$3:$G$8,MATCH(TRUE,INDEX($F$3:$F$8=B2,0),0))Based on the comment below by Keith, I have realized the above INDEX & MATCH function is an overkill and simple INDEX & MATCH below works perfectly and much faster than above combinations.

=INDEX($G$3:$G$8,MATCH(B2,$F$3:$F$8,0))SUMPRODUCT

=SUMPRODUCT(--(B2=$F$3:$F$8),$G$3:$G$8)How it works<br>In my opinion, this is the shortest and efficient formula.<br>►–(B2=$F$3:$F$8) returns an array of 1/0. {0;0;0;0;0;1}<br>1 representing the relative position of the currency that meets the criteria in the exchange rate table<br>►$G$3:$G$8 returns an array of exchange rates {0.00982118;0.071507;0.740269;1;1.06172;1.25435}<br>SUMPRODUCT gets the sum of the product of the two arrays<br>=SUMPRODUCT({0;0;0;0;0;1},{0.00982118;0.071507;0.740269;1;1.06172;1.25435})=1.25435NB: This method ONLY works with numeric values.<br>BOOLEAN LOGIC

=(B2=$F$4)*$G$4+(B2=$F$3)*$G$3+(B2=$F$5)*$G$5<br>+(B2=$F$6)*$G$6+(B2=$F$7)*$G$7+(B2=$F$8)*$G$8How it works<br>The method exploits the fact that Excel recognizes internally the value of TRUE as number 1 and value of FALSE as 0.<br>Firstly, Compare the currency in the price list table with the currency in the exchange rate. This results to TRUE/FALSE which Excel recognizes as 1/0.<br>=(0)*$G$4+(0)*$G$3+(0)*$G$5<br>+(0)*$G$6+(0)*$G$7+(1)*$G$8Since only 1 test will evaluate to TRUE, if you multiply them with corresponding rates and add them up, the result will be zeros plus the correct rate<br>=0+0+0<br>+0+0+1.25435NB: This method also ONLY works with numeric values.<br>SUMIF

How it works<br>This is another simple alternative but works ONLY with numeric values.<br>SUMIF function returns a sum of all numbers in a range of cells that meet a certain criterion.<br>syntax =SUMIF(Range, Criterion, [sum_range])<br>Range–Currencies to be evaluated using our criterion<br>Criterion–the...

match rept function index false works

Related Articles