SOLVED

How to do INDEX(MATCH() or XLOOKUP() with nested OR()?

Brass Contributor

1.png

I have two tables and need assistance with one main issue but I think I may have discovered a second I couldn't solve. 

 

Main Issue: I look at the table on the left (A:F) in column C and match that in table on the right (H:M) for column H. I then take what's in columns B and C for that specific matching account and paste in the matching area in column K and L. I create a concatenated key lookup so I can connect both tables (columns F and M):

=[@[Linking Account]]&" "&[@Account]&" "&[@[Account Name]]

 

I need to fix the N/As. How do I make a lookup or INDEX(MATCH() that does an OR() with this key I created?

 

Second issue I noticed while I was reviewing: did I do that right with linking the tables? Could there be an easier way to link them? I have to create the concatenation with the three cells because I can have more than one account hit into that linking account in the second table.

 

Thank you for any help.

12 Replies
i see that you are using XLOOKUP() which is great because the next parameter for XLOOKUP is [if_not_found] so just put whatever you want instead of N/A there. I would help more but you haven't said what that "OR" should be that you are referring to. If it can't find that exact account combination then what do you want?
Thank you.

I apologize. Let me give details.

The NAs are supposed to fall in line with the others there.

For example:

Column C matches column H for C2 (where the XLOOKUP returns correctly) and also for C3 but the lookup returns an NA.

Where the OR would be needed is the in K2 and L2 as well.

Because the first two rows actually match for C2 and C3 in H2, the accounts in A2 and A2 differ at the end at 100100XXX at the very end three.

The OR would need to look at both
100100 100100100 Name1
100100 100100200 Name2 and return DifferentName1 instead of the NA.

This is true for the other NAs. The very slight difference in the account numbers (column A) makes it tricky since the concatenation in columns D and M can’t handle both
100100 100100100/100100200 Name1/Name2

In my real data this actually could be up to 10 in a single group.

Sorry for not explaining.
best response confirmed by Jpalaci1 (Brass Contributor)
Solution

@Jpalaci1 i'm sorry but maybe I'm still not following. Why not just use the "linking Account" in the XLOOKUP instead of the created Key?

=XLOOKUP([@[Linking Account]],Table2[Linking Account],Table2[Linking Account Name])

or if you only want to 'fall back' to that less specific match condition then add a second xlookup in that if_not_found criteria like this:

=XLOOKUP([@[Created Key]],Table2[Created Key],Table2[Linking Account Name],XLOOKUP([@[Linking Account]],Table2[Linking Account],Table2[Linking Account Name]))

the problem is that in your simple example both give the same results (the first I put in col E and the latter I put in col F)

Thank you for this.

I can’t use the Linking Account because it has a many-to-many relationship.

What I mean in is Linking Account
100100 can be to
100100100
100100200
100100300
Until it changes to say
200100100

And in those 100100XXX accounts can fall under the main Linking Account 100100 but 100100 has AccountName1, 2, 3, and so on which say 100100100 and 100100200 land to AccountName1 but 100100100300 only hits to AccountName2 with the rest hitting to AccountName3.

I created the logic since I was under pressure and may have painted myself into a corner and may need to rethink it.

Definitely will test your logic tomorrow and report back and use your suggestions.

Thank you so much for the help and any continued help.

I’ll play around with my source data and report back tomorrow on it.
Forgot to mention my logic works perfectly since everything matched to one but now that I’ve increased my sample size I now have multiples hitting one now. This is why I was looking at an OR.
what is the original dataset before you were halfway to your solution that you're having problems with

@Yea_So @mtarler 

 

I checked against my example to my real data and the examples are good. When I created the fake data I used the real as an example.

 

I can't use the Linking Account because a LOOKUP would return the first and only first result because for example account 100100 has 4 accounts under it and the key of Linking Account, Account, and Account Name creates a unique key.

 

I actually found a way to fix the issue. I used second table (H:M) but adding a line after each entry and have that pasted in. In the screenshot below (#2) I just made a new row in the table and manually added Linking account, Linking Account Name, and Linking Account Detailed but this field varies over more than 1500 lines then pasted the Account and Account Name to create the key:

2.png

 

My problem with this is the original source data is over 1500 lines and do so it very manual and columns H:J come from a data source so when there are lines/Linking Accounts added in master data I'd have to rebuild each time the data come in or carefully paste in the correct place as H:J come in a specific order that must be maintained. I have it setup now that when new data comes from master data for H:J I can simply paste in and retain all formats/keys that are XLOOKUPed with no issue (unless there are new lines but I usually verify my data by ensure if there's any new lines and prep my data so it can accommodate those changes effectively). New lines are added every so often but only come maybe 10-20 at a time at a handful times throughout the year.

 

This could work if I really need to (doing what I did in screenshot #2) but it's not the most ideal. 

 

@Jpalaci1 

 

I can't suggest a variant to your solution because you started with a solution you are implementing without showing us the sample of the original dataset.  Your solution might get you on the right track or it might not, but without seeing the sample of original dataset and what you're trying to accomplish or to suggest an alternate solution or angle I cannot begin to think of it as you started your question with the solution you are trying to make work.

 

If you could show a sample of the original dataset and explain to us what your desired/expected outcome might allow us to suggest a variant.  From what I can gather from the conversation, a power query + data model with set table data relationships + power pivot path might be a good variant, but then again I do not know what the original dataset looks like and I do not know what your expected results are.

I can’t share the original but I worked through before my last post to see if it works the exact same way and it does.

The example data I have hear follow the same logic to complete what I need done.
so I'm not sure why the alternative/2nd option I sent doesn't work for you. In that option, if the created key can't be found (i.e. that specific account number doesn't exist in the other list, only then fall back and use the linking account)? If there is some other logic you prefer then you need to explain that for us to help. For example if trying to come up with help for you I have been considering and wondering the answer many questions including the following:
a) if you use a 'fall back' you have to also ignore the name so now you are just comparing account number to a 'fall back' account number, is that any more valid than just using the linking account
b) does the 'fall back' have to consider multiple options at the same level. So if 100100300 can't be found then it must use 100100200 or is 100100100 acceptable/preferred? or any account starting with 100100xxx can be used?
c) do account numbers have multiple levels for the same initial sequence. So if there is a 100100100 could there also be a 100100? and if so is that a preferred back up or not?
d) the example you gave has all the accounts in sequence. is that a guarantee? or just for the example. So 100100200 came after 100100100. So can we assume that to be true and use that order to say find the account in the list just before?
e) will the accounts always increment in 100s? so it will also be 100, 200, 300 or might it skip 100,300, 600, ... or have other numbers like 104, 108, 225, ...?
f) is there a fixed limit on the number of levels? In the data example I believe you had 3 levels 100100100 but in a response you went out to 4 levels 100100100100.

I'm not saying yours doesn't work. I was answering other replies and haven't tested yours yet.
Thank you for the help. This worked.
1 best response

Accepted Solutions
best response confirmed by Jpalaci1 (Brass Contributor)
Solution

@Jpalaci1 i'm sorry but maybe I'm still not following. Why not just use the "linking Account" in the XLOOKUP instead of the created Key?

=XLOOKUP([@[Linking Account]],Table2[Linking Account],Table2[Linking Account Name])

or if you only want to 'fall back' to that less specific match condition then add a second xlookup in that if_not_found criteria like this:

=XLOOKUP([@[Created Key]],Table2[Created Key],Table2[Linking Account Name],XLOOKUP([@[Linking Account]],Table2[Linking Account],Table2[Linking Account Name]))

the problem is that in your simple example both give the same results (the first I put in col E and the latter I put in col F)

View solution in original post