+ Reply to Thread
Results 1 to 11 of 11

Embedding Xlookup into IF

  1. #1
    Registered User
    Join Date
    11-08-2012
    Location
    USA
    MS-Off Ver
    365
    Posts
    22

    Embedding Xlookup into IF

    Good afternoon all,

    I am looking to use Xlookup in an If statement with and, but I'm struggling.

    Data is below in columns A, B, C. I want to loop this and search a concatenated A&B, returning C, and if A&B equal 1 and 2, return a value. However, I don't think Xlookup is what I want necessarily, but am not wanting to give up on it yet.


    A M022C58659 1
    B M022C58659 1
    C M022C58659 1
    D M022C58659 1
    E M022C58659 1
    A M022C58659 2
    B M022C58659 2
    C M022C58659 2
    D M022C58659 2
    E M022C58659 2

    =IF(AND((XLOOKUP(A2&B2, A:A&B:B, C:C)=1), (XLOOKUP(A2&B2, A:A&B:B, C:C)=2)), "Y")

    Trying to do this without moving to VB as I'm very rusty with VB.

    Thank you for any help.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Embedding Xlookup into IF

    Please upload a workbook or a representative cut down copy, anonymised if necessary. It is always easier to advise if we can see your request in its context.

    Show a before and after situation with manually calculated results, explaining which information is data and which is results, and if it's not blindingly obvious how you have arrived at your results some explanatory notes as well.

    To upload a file click the Go Advanced button at the foot of your post, look underneath the post area for the Manage Attachments section and take it from there.

    It's also confusing since when you mention columns A B & C and your data contains rows with values starting A, B or C

    It may be simpler to concatenate the A,B & C values in a helper column but no doubt an example workbook will help.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    11-08-2012
    Location
    USA
    MS-Off Ver
    365
    Posts
    22

    Re: Embedding Xlookup into IF

    Sorry about that. As I was searching, I noticed the banner.

    Column E shows my desired output.

    Sorry for the confusion and yes, didn't help with the data being "A, B....."
    Attached Files Attached Files

  4. #4
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2506
    Posts
    13,792

    Re: Embedding Xlookup into IF

    I am not confident I have interpreted correctly. However this will match expected output and resembles the description (I think).

    In cell E2 try this formula and copy down.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Dave

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Embedding Xlookup into IF

    Would you explain with reference to specific cell references how you obtain the Desired output.

    i.e. comment on what calculations/rules you are applying to arrive at the results.

    Is this a much simplified example and does it represent the size of your actual data? We often find that when we give an answer to what is a trivial non representative example when the solution is used with the real world data it doesn't work because of factors like string length and other stuff which is important but hasn't been mentioned.

  6. #6
    Registered User
    Join Date
    11-08-2012
    Location
    USA
    MS-Off Ver
    365
    Posts
    22

    Re: Embedding Xlookup into IF

    Thank you. I believe I was overcomplicating it seeking a lookup solution. Per Richard's comment below, my data is more complex, but I was using a simplified version to troubleshoot.

  7. #7
    Valued Forum Contributor
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    988

    Re: Embedding Xlookup into IF

    If your data could have duplicates then this would work if the values of column C are always 1 or 2:

    =IF(COUNTIFS($A$2:$A$9,A2,$B$2:$B$9,B2,$C$2:$C$9,1)>0,IF(COUNTIFS($A$2:$A$9,A2,$B$2:$B$9,B2,$C$2:$C$9,2)>0,"BOTH",1),2)

  8. #8
    Registered User
    Join Date
    11-08-2012
    Location
    USA
    MS-Off Ver
    365
    Posts
    22

    Re: Embedding Xlookup into IF

    Thank you. Is a XLOOKUP route achievable in something like this? Just looking for another way to skin a cat, not that the countif embedded into the if isn't viable.

  9. #9
    Valued Forum Contributor
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    988

    Re: Embedding Xlookup into IF

    XLOOKUP will always return the first match, so if you wanted to use it then you would need to build in the 1 and 2 in column C. Loosely following your original attempt, this would give your expected results:

    =IF(AND((XLOOKUP(A2&B2&1, A:A&B:B&C:C, C:C, 0)=1), (XLOOKUP(A2&B2&2, A:A&B:B&C:C, C:C, 0)=2)), "BOTH", XLOOKUP(A2&B2, A:A&B:B, C:C))

    Note I have added 0 as the "if not found" parameter for XLOOKUP, without this it will not work as it returns an error if the value is not found. However I would say XLOOKUP is not the best function to use if you are just checking whether something exists.

    Another alternative would be to use MATCH:

    =IF(ISNUMBER(MATCH(A2&B2&1,A:A&B:B&C:C,0)),IF(ISNUMBER(MATCH(A2&B2&2,A:A&B:B&C:C,0)),"BOTH",1),2)

  10. #10
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2506
    Posts
    13,792

    Re: Embedding Xlookup into IF

    @ mprice214

    Please update your profile. The use of XLOOKUP indicates you are using Office 365. Members often tailor solutions with that in mind.

    If you are not familiar with how to update your profile find the dark blue menu at the top of this page that says
    Forum Actions
    . Click that and 'Edit Profile'.

  11. #11
    Registered User
    Join Date
    11-08-2012
    Location
    USA
    MS-Off Ver
    365
    Posts
    22

    Re: Embedding Xlookup into IF

    I really appreciate this explanation. It is very helpful. Thanks again.

+ 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. If this do this XLOOKUP otherwise do this XLOOKUP
    By MattKoleczko in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-21-2022, 08:14 AM
  2. [SOLVED] Xlookup in PQ
    By Excelski in forum Excel General
    Replies: 7
    Last Post: 09-09-2021, 07:15 AM
  3. Lookup xLookup or something..
    By xKelly in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-06-2021, 09:24 PM
  4. Two-way Xlookup
    By Ballet4ever in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-28-2021, 10:11 PM
  5. [SOLVED] Xlookup with VBA, need some help!
    By CSimm in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-19-2021, 03:14 PM
  6. Xlookup & sum
    By lynusann in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-19-2020, 11:04 PM
  7. Sum Function with Xlookup
    By sawaccouniting in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-07-2020, 10:10 PM

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