• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

XLookup Question

Hello,

I have what I would think would be an easy solution, but I can't figure it out. Can you help?

On the attached file, I would like a formula in column C that will lookup the department name in column B and return the appropriate value from column G, it being August. Next month, I will update the current month to be September in cell C4. I want the change in cell C4 to trigger the formula to return the correct value for the month selected.

The old VLookup might work here by specifying the column number to use with an IF formula. But I thought XLookup would work somehow.

Paul
 

Attachments

  • Variance Lookup.xlsx
    25.2 KB · Views: 8
Hi, @PaulFogel123!

If Dept. Name is changing his order compare to Dept Name table lookup, then you can use this formula:
Java:
=XLOOKUP(B6:B58,E6:E58,INDEX(F6:Q58,,MATCH(C4,F5:Q5,)))
But if it's the same order, you can use:
Java:
=INDEX(F6:Q58,,MATCH(C4,F5:Q5,))
Another option could be:
Java:
=FILTER(F6:Q58,IFERROR(F5:Q5=C4,))
Blessings!
 
As you have it, you do not need to look up the Dept Name because the variance table is already in the correct order. An entire column is returned by
Code:
= XLOOKUP(monthCur, monthHdr, variance)
If the list of departments do not match the row headers then a second nested lookup can be used to return a partial column
Code:
= XLOOKUP(
    Dept,
    DeptHdr,
    XLOOKUP(
      monthCur,
      monthHdr,
      variance
    )
  )
Whilst I think of it, if you only seek the result for a single department then it is possible to lookup a row and a columns from the variance table and then use range intersection to return the reference to a single cell.
Code:
= XLOOKUP( Dept, DeptHdr, variance )
  XLOOKUP(monthCur, monthHdr, variance)
 
Last edited:
Hi, @PaulFogel123!

If Dept. Name is changing his order compare to Dept Name table lookup, then you can use this formula:
Java:
=XLOOKUP(B6:B58,E6:E58,INDEX(F6:Q58,,MATCH(C4,F5:Q5,)))
But if it's the same order, you can use:
Java:
=INDEX(F6:Q58,,MATCH(C4,F5:Q5,))
Another option could be:
Java:
=FILTER(F6:Q58,IFERROR(F5:Q5=C4,))
Blessings!

Hi John,
I think this formula,
XLOOKUP(B6:B58,E6:E58,INDEX(F6:Q58,,MATCH(C4,F5:Q5,)))
will be more flexible, just in case I change the list order in one of the tables.
Thank you.
 
Back
Top