Power Query Course in Spanish
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 9 of 9

Thread: Can I use index match within an IF statement?

  1. #1
    Board Regular
    Join Date
    May 2004
    Posts
    78
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Can I use index match within an IF statement?

    I am using index match to look up a value (test score) based on the student selected. No problems, working fine.

    Now I'd like the returned test score to be change according to the assignment selected.

    I've got 2 ranges at the moment storing the test scores (and there may be more in future) and have set up radio buttons to select which range to read the result from based on the student name as the lookup value.

    It's working if I have the test results showing in different cells...ie. 2 difference index match functions.

    But I want the test result in the same cell.
    I've tried using an IF statement but whilst it continues to work if the first option button is selected, I get FALSE if the second one is selected.

    =IF(AU5=1,INDEX(U5:U13,MATCH(A5,A5:A30,0),IF(AU5=2,INDEX(AQ5:AQ18,MATCH(AF5,AF5:AF18,0)))))

    Can anyone see the problem or select a better way?

    Thanks

    Liz

  2. #2
    Board Regular
    Join Date
    Aug 2012
    Posts
    245
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Can I use index match within an IF statement?

    Hi Liz,

    May I ask why you have the match at all? It will always equate to 1. You are saying in the range A5:A30, how many cells in before the value matches that of A5.

    Do you see what I mean? I dare say this will be contributing to the issue.

    Also, if you are getting FALSE, then AU5 must equal something other than 2?

    Cheers
    JB

  3. #3
    Board Regular
    Join Date
    May 2004
    Posts
    78
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Can I use index match within an IF statement?

    Hi,
    I was using match because I thought it was a more efficient way than using VLOOKUP.

    AU5 either contains 1 or 2 as it is the linked cell from the radio option buttons.

    However, it does work with Vlookup so maybe I will stick to that method
    Last edited by 69liz; Nov 24th, 2017 at 02:07 PM.

  4. #4
    Board Regular
    Join Date
    Aug 2012
    Posts
    245
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Can I use index match within an IF statement?

    Ok, I think I get where you're coming from, but both of those Match() functions will ALWAYS result in 1, so may as well be replaced with '1'. Presumably not though, as I don't think that's what you're aiming for, but:

    MATCH(A5,A5:A30)

    MATCH function returns an integer, equal to how far it has to go into your range before it finds the value.

    You are saying the value is whatever is in A5, and the range is A5:A30, so no matter the configuration, this will always return 1, as the first cell in the range is A5, and of course it will always be equal to itself!

    Same goes for MATCH(AQ5,AQ5:AQ18).

    I think you need to post a screenshot of your sheet so we can get a visual on what you're trying to achieve.

  5. #5
    Board Regular
    Join Date
    May 2004
    Posts
    78
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Can I use index match within an IF statement?

    Unfortunately I don't seem to be able to post screenshots. Not sure why. I don't have permission apparently.

    Anyway, I've got it working with Vlookup.

    The value A5 would change in the final version. Here it was just used to test out the formula. A5 holds the students name and in the final version this will be different.

  6. #6
    Board Regular
    Join Date
    Aug 2012
    Posts
    245
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Can I use index match within an IF statement?

    ohhh, so 'A5' was more of a placemarker in the formula, which would eventually be something completely different to the cells address, and the cell value of A5?

    If that's the case, you may want to use something more like a variable instead, like StudentName in italics. The A5,A5:A30 really threw me!

    If you mean the value will change, but you are referring to the value of cell A5, then I still fear you may run into issues.

    Glad you're sorted though!

    Cheers
    JB

  7. #7
    Board Regular
    Join Date
    Aug 2012
    Posts
    245
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Can I use index match within an IF statement?

    Oh, and you can't post screen shots here. You have to link to an uploaded one.

    There's some stuff on that here:

    #post2507729https://www.mrexcel.com/forum/about-...ml#post2507729

  8. #8
    Board Regular
    Join Date
    May 2004
    Posts
    78
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Can I use index match within an IF statement?

    Thanks JB. Sorry for the confusion. I will see how it pans out. Thanks for the heads up about screenshots. Presumably the same for sharing actual Excel files.
    Really appreciate you taking the time to help. Liz

  9. #9
    Board Regular
    Join Date
    Aug 2012
    Posts
    245
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Can I use index match within an IF statement?

    You're welcome. Good luck!

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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