WISDOMBYDATA
  • BLOG
    • Blog Guide
    • Blog History
  • EXCEL
    • Functions & Formulas
    • VBA & Macros
    • VLOOKUP
    • Pivot Tables
    • Conditional Formatting
    • Tricks & Shortcuts
  • BI
    • SAP BOBJ/BW
    • Tableau
  • SQL
  • ABOUT
    • About WBD
    • About Me

Tricky MS Excel interview Question - Conditional IF statement

3/10/2019

0 Comments

 

Few months ago I was asked to solve an Excel problem during a job interview.  While the solution seemed to be simple at first glance, the question was a loaded one and took me some time to figure out the answer (I eventually got it right). Here is what the spreadsheet looked like:
Picture
It contained 6 columns and three rows of data. The ask was to create a formula in the 7th column  (i.e. column G) that would return “Pass” ONLY when the values in columns C and F were BOTH equal to “Pass” and return “Fail” if otherwise. I initially attempted using the formula below :

=IF(AND(C2="Pass",F2="Pass"),"Pass","Fail")

But this formula kept on returning the “#N/A” error!!!  
Picture
After more contemplation, I noticed that the reason for the “#N/A” error is that the values in columns C and F were themselves the result of a formula which used the values in columns A, B, and D, E respectively. For example:

=IF((TRIM(A2)<>TRIM(B2)),"Fail","Pass")

Moreover, the values in columns A, B, D and E were also themselves the results of a VLOOKUP from different tabs. All of this cross-referencing causes some confusions for EXCEL resulting in the #N/A output showing up for the IF statement. As such, my IF(AND formula was not functioning as intended when I referenced columns C and F directly.

The solution is to input the formula used in columns C and F within the IF statement and to use an IF(OR formula instead of an IF(AND formula as shown below:
​
=IF(OR((TRIM(A2)<>TRIM(B2)),(TRIM(D2)<>TRIM(E2))),"Fail","Pass")
Picture
​This formula performs the same calculations as in columns C and F and therefore directly references columns A, B, D and E and as such it returns the desired values as shown below
Picture

0 Comments



Leave a Reply.

    Categories

    All
    BI
    EXCEL
    MISC
    SQL

    Archives

    June 2020
    May 2020
    April 2020
    March 2020
    February 2020
    December 2019
    November 2019
    October 2019
    September 2019
    August 2019
    July 2019
    June 2019
    May 2019
    April 2019
    March 2019
    February 2019
    January 2019
    December 2018
    November 2018
    October 2018
    September 2018
    August 2018
    July 2018
    June 2018
    May 2018
    April 2018
    March 2018
    September 2017
    August 2017
    July 2017
    June 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    May 2015
    April 2015
    March 2015
    February 2015
    January 2015
    December 2014
    November 2014
    October 2014
    September 2014
    August 2014
    April 2014
    March 2014
    February 2014
    January 2014
    December 2013
    November 2013

Powered by Create your own unique website with customizable templates.
  • BLOG
    • Blog Guide
    • Blog History
  • EXCEL
    • Functions & Formulas
    • VBA & Macros
    • VLOOKUP
    • Pivot Tables
    • Conditional Formatting
    • Tricks & Shortcuts
  • BI
    • SAP BOBJ/BW
    • Tableau
  • SQL
  • ABOUT
    • About WBD
    • About Me