Compare & combine tables using dynamic arrays

sharshra

Active Member
Joined
Mar 20, 2013
Messages
404
Office Version
  1. 365
I´m trying to compare 2 tables & get an output based on the following logic.

Table 1 is the source table. Table 2 is for comparison. In table 1, I want to take the names having 'status=ok' & check if they have 'keep<>y' in table 2. Take those values & provide an output. I´m trying to use dynamic arrays to the the desired output, but not successful. I'm sure it is quite simple for the experts in this forum. Can you help please?

Table 1
excel problems.xlsx
BCD
1table 1
2namestatusdetails
3dfdsokkjhk
4gfhnot ok
5uirnot ok5t
6qewroknmnm
7xcvzokxcx
8cmvnokdsds
9dhgdhokoioi
10teywunot ok
11sdfok
12gdok
13hkfinot ok
Sheet9


Table 2
excel problems.xlsx
GHI
1table 2
2namekeepcomments
3qewr34u
4dfdsy
5xcvz
6sdfncom2
7cmvny
8uirnno7
9dhgdhlk8y
Sheet9


Desired output
excel problems.xlsx
LMNOP
1desired output
2namestatusdetailskeepcomments
3qewroknmnm34u
4xcvzokxcx
5dhgdhokoioilk8y
6sdfokncom2
Sheet9
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hello, here is an attempt:

Excel Formula:
=LET(
a,FILTER(B3:D13,ISNUMBER(XMATCH(B3:B13,G3:G9))),
b,XMATCH(CHOOSECOLS(a,1),G3:G9),
c,CHOOSEROWS(H3:I9,b),
d,HSTACK(a,c),
e,FILTER(d,(CHOOSECOLS(d,2)="ok")*(CHOOSECOLS(d,4)<>"y")),
IF(ISBLANK(e),"",e))
 
Upvote 1
Solution
Python formula as an alternative (entered by =PY and Tab)
Python:
table1 = xl("B2:D13", headers=True)
table2 = xl("G2:I9", headers=True)
byStatus = table1[table1["status"] == "ok"]
byKeep = table2[table2["keep"] != "y"]
table3 = pd.merge(byStatus, byKeep, on="name").replace({None: ""})
Book1
ABCDEFGHIJKLMNOP
1table1table 2
2namestatusdetailsnamekeepcommentsnamestatusdetailskeepcomments
3dfdsokkjhkqewr34uqewroknmnm34u
4gfhnot okdfdsyxcvzokxcx
5uirnot ok5txcvzdhgdhokoioilk8y
6qewroknmnmsdfncom2sdfokncom2
7xcvzokxcxcmvny
8cmvnokdsdsuirnno7
9dhgdhokoioidhgdhlk8y
10teywunot ok
11sdfok
12gdok
13hkfinot ok
Sheet1
 
Upvote 1
I´m trying to get similar results using another method & getting error. Not sure what is going wrong. Can the experts point me the mistake please?
excel problems.xlsx
B
15#VALUE!
merge tables
Cell Formulas
RangeFormula
B15:D21B15=LET( srct1, B3:D13, srct1Name, B3:B13, srct1Status, C3:C13, reft2, G3:I9, reft2Name, G3:G9, reft2Keep, H3:H9, tSrcStatusOk, FILTER(srct1,srct1Status="ok"), tRefKeepNoY, FILTER(reft2, reft2Keep="y"), fOutput, MAP(tSrcStatusOk, LAMBDA(x, XLOOKUP(x,tRefKeepNoY, CHOOSECOLS(tRefKeepNoY,3)))), fOutput)
Dynamic array formulas.
 
Upvote 0
An alternative with Power Query

Power Query:
let
    T1 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    FilterRows = Table.SelectRows(T1, each ([status] = "ok")),
    T2=Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    FilterRows2 = Table.SelectRows(T2, each ([keep] <> "y")),
    MQ = Table.NestedJoin(FilterRows, {"name"}, FilterRows2, {"name"}, "Table2", JoinKind.FullOuter),
    #"Expanded Table2" = Table.ExpandTableColumn(MQ, "Table2", {"keep", "comments"}, {"keep", "comments"})

in
    #"Expanded Table2"
 
Upvote 0
Thanks, @alansidman. It's really useful.

However, I'm trying to get it using dynamic arrays with MAP or REDUCE functions, but it is going wrong somewhere. Requesting the experts to point the mistake.
 
Upvote 0
One problem could be that "tSrcStatusOk" consists of 3 columns which is then provided to XLOOKUP. As a first step e.g. use CHOOSECOLS or INDEX to limit lookup_value to one column, i.e. the one which is to be compared against lookup_array.
 
Upvote 0
@hagia_sofia, Thanks for your suggestion. I made the following changes & I could see it is working without error.

But, if I give tRefKeepNoY in XLOOKUP, it throws ·VALUE error. Why it happens? It should be possible to use the entire array instead of 1 column?

Also, if I want to pull 2nd & 3rd column from tRefKeepNoY, it throws #CALC error. Any reasons for this?

No error :giggle:
excel problems.xlsx
BCDE
15dfdsokkjhk#N/A
16qewroknmnm34u
17xcvzokxcx0
18cmvnokdsds#N/A
19dhgdhokoioi8y
20sdfok0com2
21gdok0#N/A
merge tables
Cell Formulas
RangeFormula
B15:E21B15=LET( srct1, B3:D13, srct1Name, B3:B13, srct1Status, C3:C13, reft2, G3:I9, reft2Name, G3:G9, reft2Keep, H3:H9, tSrcStatusOk, FILTER(srct1,srct1Status="ok"), tRefKeepNoY, FILTER(reft2, reft2Keep<>"y"), fOutput, MAP(CHOOSECOLS(tSrcStatusOk,1), LAMBDA(x, XLOOKUP(x,CHOOSECOLS(tRefKeepNoY,1), CHOOSECOLS(tRefKeepNoY,3)))), HSTACK(tSrcStatusOk,fOutput))
Dynamic array formulas.


#VALUE error:
excel problems.xlsx
BCDE
15dfdsokkjhk#VALUE!
16qewroknmnm#VALUE!
17xcvzokxcx#VALUE!
18cmvnokdsds#VALUE!
19dhgdhokoioi#VALUE!
20sdfok0#VALUE!
21gdok0#VALUE!
merge tables
Cell Formulas
RangeFormula
B15:E21B15=LET( srct1, B3:D13, srct1Name, B3:B13, srct1Status, C3:C13, reft2, G3:I9, reft2Name, G3:G9, reft2Keep, H3:H9, tSrcStatusOk, FILTER(srct1,srct1Status="ok"), tRefKeepNoY, FILTER(reft2, reft2Keep<>"y"), fOutput, MAP(CHOOSECOLS(tSrcStatusOk,1), LAMBDA(x, XLOOKUP(x,tRefKeepNoY, CHOOSECOLS(tRefKeepNoY,3)))), HSTACK(tSrcStatusOk,fOutput))
Dynamic array formulas.


#CALC
excel problems.xlsx
B
15#CALC!
merge tables
Cell Formulas
RangeFormula
B15B15=LET( srct1, B3:D13, srct1Name, B3:B13, srct1Status, C3:C13, reft2, G3:I9, reft2Name, G3:G9, reft2Keep, H3:H9, tSrcStatusOk, FILTER(srct1,srct1Status="ok"), tRefKeepNoY, FILTER(reft2, reft2Keep<>"y"), fOutput, MAP(CHOOSECOLS(tSrcStatusOk,1), LAMBDA(x, XLOOKUP(x,CHOOSECOLS(tRefKeepNoY,1), CHOOSECOLS(tRefKeepNoY,2,3)))), HSTACK(tSrcStatusOk,fOutput))
 
Upvote 0
Both problems seem to be of the same kind as the previous one: XLOOKUP will work here only with one column in any argument, e.g. the latter could work with XLOOKUP if you HSTACK two XLOOKUPs, one per column (the original bypass above was to use CHOOSEROWS).
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,215
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top