Two way vertical and horizontal lookup

%3CLINGO-SUB%20id%3D%22lingo-sub-3066383%22%20slang%3D%22en-US%22%3ETwo%20way%20vertical%20and%20horizontal%20lookup%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3066383%22%20slang%3D%22en-US%22%3E%3CP%3EI%20want%20a%20formula%20to%20lookup%20a%20date%2C%20establish%20whats%20it%20falls%20onto%20using%20the%20week%20ending%20date%2C%20match%20that%20against%20the%20employee%20name%20and%20return%20the%20intersecting%20value.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20example%2C%20I%20want%20to%20see%20James'%20potential%20hours%20for%208%2F1%2F21%2C%20which%20should%20return%2032%20(B16).%20If%20the%20date%20was%2004%2F04%2F21%20then%20it%20should%20return%2025.6%20for%20James%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20dates%20in%20my%20dataset%20are%20by%20week%20ending%20e.g.%20Sunday%2010%2F1%2F21%20so%20a%20date%20lookup%20would%20need%20to%20know%20that%208%2F1%2F21%20falls%20under%20that%20week%20and%20returns%20the%20intersecting%20value%20against%20the%20employee%20name%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20tried%20the%20following%20xlookup%20to%20no%20avail%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3DXLOOKUP(B3%2CA13%3AA16%2CXLOOKUP(B4%2CB12%3AAW12%2CB16%3AAW16%2C%22not%20found%22%2C1%2C1))%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22MHir03_0-1642629278367.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F340804i2605B1EE167E4DC5%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22MHir03_0-1642629278367.png%22%20alt%3D%22MHir03_0-1642629278367.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3066383%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Contributor

I want a formula to lookup a date, establish whats it falls onto using the week ending date, match that against the employee name and return the intersecting value.

 

For example, I want to see James' potential hours for 8/1/21, which should return 32 (B16). If the date was 04/04/21 then it should return 25.6 for James

 

The dates in my dataset are by week ending e.g. Sunday 10/1/21 so a date lookup would need to know that 8/1/21 falls under that week and returns the intersecting value against the employee name

 

I have tried the following xlookup to no avail

 

=XLOOKUP(B3,A13:A16,XLOOKUP(B4,B12:AW12,B16:AW16,"not found",1,1))

 

MHir03_0-1642629278367.png

 

 

7 Replies

@MHir03 

=IFERROR(INDEX($B$13:$AW$16, XMATCH(B3, $A$13:$A$16), XMATCH(B4, $B$12:$AW$12, 1)), "not found")

@MHir03 

In principle, what you are doing is correct.

= XLOOKUP(
    name, 
    employee, 
    XLOOKUP(d,wkEnding,hours,"",1)
  )

so the problem is in the detail.  Maybe looking up a numeric datavalue against a text date.

Thank you Hans, this seems to have done it. Why would did you use IFERROR and XMATCH over XLOOKUP? wouldn't the latter be far easier?

I'm expecting you'll see there are limitations to xlookup relevant to my dataset which would not make it work as i wasnt able to implement it so far. I confirm the dates are being handled as dates in excel and not as numbers

@MHir03 

The third argument of your XLOOKUP formula should be an array, but it is XLOOKUP(B4,B12:AW12,B16:AW16,"not found",1,1) which returns a single value, not an array.

@Hans Vogelaar 

Well spotted.  I haven't used a direct cell reference for so long that I tend to see them but not register their content.  I simply replaced the reference by a two dimensional array 'hours' and, of course, the formula worked perfectly.

Hi both, struggling to see the error in the formula, the third argument is referencing a return array B16:AW16 so what am I doing wrong?

@MHir03 

Your original formula has two XLOOKUPS:

 

=XLOOKUP(B3,A13:A16,XLOOKUP(B4,B12:AW12,B16:AW16,"not found",1,1))

 

The first (outer) XLOOKUP has arguments:

1. Lookup value: B3

2. Lookup array: A13:A16

3. Return array: XLOOKUP(B4,B12:AW12,B16:AW16,"not found",1,1)

The return array argument is an XLOOKUP formula that returns a single value, not an array.