+ Reply to Thread
Results 1 to 13 of 13

IF Comparison Function Not Returning Correct Data

  1. #1
    Registered User
    Join Date
    01-24-2014
    Location
    NC, USA
    MS-Off Ver
    Excel 2010
    Posts
    4

    IF Comparison Function Not Returning Correct Data

    I'm trying to compare three formula results and return the largest number. Ex.:

    22 17 9 22

    The first three numbers are formula results and the last is the following formula:

    =IF(O5>P5,O5,IF(P5>Q5,P5,Q5))

    Unfortunately, with the list below, you can see the last number (the comparison formula) isn't always the greater of the three:

    22 17 9 22
    20 17 9 20
    0 17 9 9
    0 13 9 9
    0 13 9 9
    0 12 9 9
    0 12 9 9
    0 12 9 9
    0 12 9 9
    0 11 9 9
    0 11 9 9
    0 10 9 9
    0 0 8 8
    0 0 7 7
    0 0 7 7

    I've also tried other formulas, with no success:

    =LARGE(O5:Q5,1)
    =MAX(O5:Q5)
    =IF(MAX(O5:Q5)=O5,O5,IF(MAX(O5:Q5)=P5,P5,IF(MAX(O5:Q5)=Q5,Q5,"Error")))

    What's odd is that if I create the formulas above independent of the specific formula data (O5, P5, and Q5) and just type in numbers, those formulas do exactly what they should. Can I not compare data returned though formula calculations?

    Any suggestions or feedback would be greatly appreciated.

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: IF Comparison Function Not Returning Correct Data

    Looks like your numbers in the first three columns may be stored as text, not numbers... Hard to say without an attached workbook, though.

    Convert to numbers, or use something like:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Contributor
    Join Date
    12-22-2010
    Location
    Rio, Brazil
    MS-Off Ver
    Excel 2010, 2016
    Posts
    209

    Re: IF Comparison Function Not Returning Correct Data

    Try this array formula

    =MAX(O5:Q5+0)

    confirmed with Ctrl+Shift+Enter, not just Enter
    Marcelo Branco

  4. #4
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,499

    Re: IF Comparison Function Not Returning Correct Data

    If I understand you correctly, you get the correct results if you type in the numbers exactly but not as they are in the sheet?
    Using your numbers and the formula I get the correct results based on what you want so I wonder if they are actually text or have some hidden space contained in those cells. Have you checked for that?
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

  5. #5
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,499

    Re: IF Comparison Function Not Returning Correct Data

    Hey mlcb, max as =max(O5:Q5) works too, why the plus 0 and array (just curious)?

  6. #6
    Registered User
    Join Date
    01-24-2014
    Location
    NC, USA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: IF Comparison Function Not Returning Correct Data

    Your formula did it:

    =MAX(--O5,--P5,--Q5)

    I'm not an expert, so the hyphens you added are new to me. What functionality did that change?

  7. #7
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,499

    Re: IF Comparison Function Not Returning Correct Data

    Nice formula Olly, the -- making text into numbers.

  8. #8
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: IF Comparison Function Not Returning Correct Data

    Quote Originally Posted by Sambo kid View Post
    Hey mlcb, max as =max(O5:Q5) works too, why the plus 0 and array (just curious)?
    The array formula steps through each cell in the range, and adds 0 to it, which makes Excel convert the text to values


    Quote Originally Posted by emlit View Post
    I'm not an expert, so the hyphens you added are new to me. What functionality did that change?
    It makes Excel convert the text to values

  9. #9
    Forum Contributor
    Join Date
    08-29-2011
    Location
    Atlanta
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: IF Comparison Function Not Returning Correct Data

    If Sambo kid's suggestion doesn't work, try multiplying each of the three formulas by 1 (=[FORMULA]*1). Then, the MAX formula should work.

    Also, the first formula you used compares O against P and if O is greater, it returns O and ignores the value in Q. Only if O is less than P does your formula evaluate Q.

    If you truly want the largest of the three, stick with MAX

  10. #10
    Registered User
    Join Date
    01-24-2014
    Location
    NC, USA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: IF Comparison Function Not Returning Correct Data

    I see. Very nice, indeed.

    The cells are formatted as numbers, however, but I'll certainly keep that trick in the back of my mind.

    Many thanks, all.

  11. #11
    Forum Contributor
    Join Date
    08-29-2011
    Location
    Atlanta
    MS-Off Ver
    Excel 2007
    Posts
    171

    Re: IF Comparison Function Not Returning Correct Data

    sorry, looks like my response was too delayed

  12. #12
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,499

    Re: IF Comparison Function Not Returning Correct Data

    ATLGator, gotta be quick around here.
    I was typing my first post and there were no other responses, I hit post and there were two ahead of me.

  13. #13
    Registered User
    Join Date
    01-24-2014
    Location
    NC, USA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: IF Comparison Function Not Returning Correct Data

    Quote Originally Posted by ATLGator View Post
    If Sambo kid's suggestion doesn't work, try multiplying each of the three formulas by 1 (=[FORMULA]*1). Then, the MAX formula should work.

    Also, the first formula you used compares O against P and if O is greater, it returns O and ignores the value in Q. Only if O is less than P does your formula evaluate Q.

    If you truly want the largest of the three, stick with MAX
    The way the formulas are set up, only numbers greater than 18 will show in O, otherwise it's a 0. I will use MAX from now on, however - I'm just used to IF statements, I suppose. Thank you for the feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Indirect function not returning correct value
    By iamskippy in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 09-16-2013, 04:28 PM
  2. [SOLVED] Returning data for Duplicates in correct order
    By ClickingNoise in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 08-12-2013, 07:08 AM
  3. Replies: 6
    Last Post: 02-22-2012, 11:26 AM
  4. Trouble returning correct formatting using comparison operators
    By mongo76 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-29-2008, 01:26 PM
  5. [SOLVED] MAX Function not returning correct value
    By Phil in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-28-2006, 05:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1