+ Reply to Thread
Results 1 to 13 of 13

XLOOKUP or FILTER matrix result expected but #VALUE! returned

  1. #1
    Registered User
    Join Date
    01-29-2024
    Location
    Amsterdam
    MS-Off Ver
    365
    Posts
    24

    XLOOKUP or FILTER matrix result expected but #VALUE! returned

    I'm using a XLOOKUP formula in a set of formulas and values that are part of the LET(...) function. I'm trying to get matching results for each row in a matrix which are searched in a second table. I believe the problem is that the formula doesn't do the match on a row by row basis, but tries to match all values at the same time.

    In other words what I'm trying to do here, is "for each row in the column of the matrix, find the corresponding value in table TAA" Only one value should match in the TAA table based on the used criteria.

    I tried to get the results by using the FILTER formula, but this also caused the #VALUE! error. In buth attempts, when I'm using a fixed value for each criteria, it works without errors (for example

    Please Login or Register  to view this content.
    I enclosed the sample sheet. The results are used as source for a graph in Excel.

    How can I get this working?

    Art.
    Attached Files Attached Files
    Last edited by dxfoxd; 04-19-2024 at 05:31 PM. Reason: Adding variables problem returned

  2. #2
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,465

    Re: XLOOKUP or FILTER matrix result expected but #VALUE! returned

    XLOOPUP causes #VALUE because the lookup array consists of 67 elements and the return array has only 24 elements.
    This must be equal.

    When you truncate the lookup matrix to the size of the return matrix, #VALUE no longer occurs, but normal values ​​are returned.

    Please try:
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by HansDouwe; 04-17-2024 at 04:02 PM.

  3. #3
    Registered User
    Join Date
    01-29-2024
    Location
    Amsterdam
    MS-Off Ver
    365
    Posts
    24

    Re: XLOOKUP or FILTER matrix result expected but #VALUE! returned

    Thx Hans! I would never come up with this, or at least not within a week or so :-)

  4. #4
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,465

    Re: XLOOKUP or FILTER matrix result expected but #VALUE! returned

    You are Welcome!

    Thanks for the feedback and rep.

    Glad to have helped .

  5. #5
    Registered User
    Join Date
    01-29-2024
    Location
    Amsterdam
    MS-Off Ver
    365
    Posts
    24

    Re: XLOOKUP or FILTER matrix result expected but #VALUE! returned

    While applying this solution to the actual dataset the problem returned, but I cannot discover why this isn't working. the TAKE/ROWS make sure that the XLOOKUP formula is limited to the number of rows of the second table. I updated the sample, where the number of records are increased and only 2 columns are added to be used for the filter criteria. However, these filters are not used in the XLOOKUP formula, but the result of XLOOKUP is again #VALUE!. What am I missing here?
    Attached Files Attached Files

  6. #6
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,465

    Re: XLOOKUP or FILTER matrix result expected but #VALUE! returned

    There is no 1 in ((TAA[taa_year]=CHOOSECOLS(flt,1))*(TAA[taa_month]=CHOOSECOLS(flt,2)) (only zeros), so the XLOOKUP can't find anything.

  7. #7
    Registered User
    Join Date
    01-29-2024
    Location
    Amsterdam
    MS-Off Ver
    365
    Posts
    24

    Re: XLOOKUP or FILTER matrix result expected but #VALUE! returned

    What do you mean? The CHOOSECOLS(flt,1) lists all years and CHOOSECOLS(flt,2) list all months that are in the filtered dataset flt.

  8. #8
    Registered User
    Join Date
    01-29-2024
    Location
    Amsterdam
    MS-Off Ver
    365
    Posts
    24

    Re: XLOOKUP or FILTER matrix result expected but #VALUE! returned

    Actually it is even more complicated. The first solution did have results, but these were incorrect. XLOOKUP did only show one value which was not the right value based on the criteria.

    The new problem is now, if I add 2 colums to the PERF table and use the same filter as used in the first sample sheet, I get a result of >7000 rows and the XLOOOKUP shows a simular result as the first solution (which is incorrect.
    However, if I add 2 criteria to the filter, I get a result of >1800 and then the #VALUE! error is back again.

    Besides that the first solution isnt working after all, I cannot understand why only the number of rows are affecting the XLOOKUP as they have the same number of columns and similar values as the first FILTER.

    In the attached spreadsheet I inserted both formulas side by side and as a last table I inderted an standalone XLOOKUP and the expected calculations. These work, but I prefer to include the XLOOKUP it in the LET formula.

    The question is still, how to accomplish this?

    Art
    Attached Files Attached Files

  9. #9
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,465

    Re: XLOOKUP or FILTER matrix result expected but #VALUE! returned

    Quote Originally Posted by dxfoxd View Post
    \The first solution did have results, but these were incorrect
    The problem is that you indicate that the formula produces a #VALUE, but you do not indicate what the expected results are and how these results should be calculated. So I can only point out what causes #VALUE. And I did that in both cases.

  10. #10
    Registered User
    Join Date
    01-29-2024
    Location
    Amsterdam
    MS-Off Ver
    365
    Posts
    24

    Re: XLOOKUP or FILTER matrix result expected but #VALUE! returned

    Compared to the first sheet, I added the s_corr and d_corr just to show when and where it goes wrong.
    The attached sheet shows 2 sets of formulas. The first one is the extended output based on the first fsolution. The second set is the formula when adding filters to the first matrix but without toutching the XLOOKUP formula. The third set shows what the output is expected based on the formula used in the second set.
    I really appreciate your help in this!
    Attached Files Attached Files

  11. #11
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,465

    Re: XLOOKUP or FILTER matrix result expected but #VALUE! returned

    This formula returns the expected results:

    PHP Code: 
    =LET(
    source,PERF,
    y,$B$1,
    m,$B$2,
    old_flt,CHOOSECOLS(FILTER(source,(PERF[perf_year]=y-1)+((PERF[perf_year]=y)*(PERF[perf_month]<=m)),"N/A"),1,2,5,6),
    flt,CHOOSECOLS(FILTER(source,(PERF[code]=$B$4)*(PERF[type]=$B$3)*((PERF[perf_year]=y-1)+((PERF[perf_year]=y)*(PERF[perf_month]<=m))),"N/A"),1,2,5,6),
    label,CHOOSECOLS(flt,1,2),
    data,CHOOSECOLS(flt,3,4),
    grp,GROUPBY(label,data,SUM,0,0),
    y_g,CHOOSECOLS(grp,1),
    m_g,CHOOSECOLS(grp,2),
    ym_t,CHOOSECOLS(TAA,1)&CHOOSECOLS(TAA,2),
    s_corr,MAP(y_g&m_g,LAMBDA(ym,XLOOKUP(ym,ym_t,CHOOSECOLS(TAA,3)))),
    s_new,CHOOSECOLS(grp,3)*(1+s_corr),
    d_corr,MAP(y_g&m_g,LAMBDA(ym,XLOOKUP(ym,ym_t,CHOOSECOLS(TAA,4)))),
    d_new,CHOOSECOLS(grp,4)*(1+d_corr),
    HSTACK(grp,s_new,d_new)) 
    Attached Files Attached Files
    Last edited by HansDouwe; 04-19-2024 at 11:54 AM.

  12. #12
    Registered User
    Join Date
    01-29-2024
    Location
    Amsterdam
    MS-Off Ver
    365
    Posts
    24

    Re: XLOOKUP or FILTER matrix result expected but #VALUE! returned

    Yes!!! Thx Hans, you're a legend! I already thought on a similar FOR EACH instruction in VB but I couldn't find an equivalent formula for Excel. MAP...LAMBDA it is!

  13. #13
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,465

    Re: XLOOKUP or FILTER matrix result expected but #VALUE! returned

    It is also possible without MAP LAMBDA:

    PHP Code: 
    =LET(
    source,PERF,
    y,$B$1,
    m,$B$2,
    old_flt,CHOOSECOLS(FILTER(source,(PERF[perf_year]=y-1)+((PERF[perf_year]=y)*(PERF[perf_month]<=m)),"N/A"),1,2,5,6),
    flt,CHOOSECOLS(FILTER(source,(PERF[code]=$B$4)*(PERF[type]=$B$3)*((PERF[perf_year]=y-1)+((PERF[perf_year]=y)*(PERF[perf_month]<=m))),"N/A"),1,2,5,6),
    label,CHOOSECOLS(flt,1,2),
    data,CHOOSECOLS(flt,3,4),
    grp,GROUPBY(label,data,SUM,0,0),
    y_g,CHOOSECOLS(grp,1),
    m_g,CHOOSECOLS(grp,2),
    ym_t,CHOOSECOLS(TAA,1)&CHOOSECOLS(TAA,2),
    s_corr,XLOOKUP(y_g&m_g,ym_t,CHOOSECOLS(TAA,3)),
    s_new,CHOOSECOLS(grp,3)*(1+s_corr),
    d_corr,XLOOKUP(y_g&m_g,ym_t,CHOOSECOLS(TAA,4)),
    d_new,CHOOSECOLS(grp,4)*(1+d_corr),
    HSTACK(grp,s_new,d_new)) 
    Attached Files Attached Files

+ 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. [SOLVED] Show left chars of xlookup result with conditions on return result
    By Tech980 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-11-2023, 07:15 AM
  2. [SOLVED] Xlookup not working as expected
    By northernwarrior in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-24-2023, 04:59 PM
  3. Replies: 11
    Last Post: 04-14-2023, 12:50 PM
  4. [SOLVED] XLOOKUP lookup_value is a returned value of a formula
    By sussington in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-17-2023, 05:53 PM
  5. [SOLVED] XLOOKUP Row and Col not finding matching value in Matrix.
    By Ochimus in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-22-2023, 02:29 PM
  6. [SOLVED] Matrix Lookup Multiple Critera returned in single cell
    By NotSwank in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 06-18-2021, 02:55 PM
  7. [SOLVED] Advanced Filter gives not the expected result
    By Harry_1101 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-05-2021, 09:59 AM

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