AIJOIN

=AIJOIN(l,r,klf,krt)

l
left array
r
right array
klf
link "key" of left array, integer or array of integers. 2 or {3,2} . 0 or ignored will be consider 1
krt
link "key" of right array, integer or array of integers. 2 or {3,2} . 0 or ignored will be consider 1

same functionality as in Power Querry join/merge scenario called Inner Join

Xlambda

Well-known Member
Joined
Mar 8, 2021
Messages
860
Office Version
  1. 365
Platform
  1. Windows
AIJOIN arrays Inner Join, same functionality as in Power Querry join/merge scenario called Inner Join. Calls ATEXTJOIN , ARRANGE , APPEND2H
l, left array, r, right array
klf: link "key" of left array, integer or array of integers. 2 or {3,2} . 0 or ignored will be consider 1
krt: link "key" of right array, integer or array of integers. 2 or {3,2} . 0 or ignored will be consider 1
Other functions on minisheet ARRANGE , APIVOT
Excel Formula:
=LAMBDA(l,r,klf,krt,
    LET(d,"|",t,"not found",kl,UNIQUE(IF(klf=0,1,klf),1),kr,UNIQUE(IF(krt=0,1,krt),1),
       cl,COLUMNS(l),ql,SEQUENCE(,cl),cr,COLUMNS(r),qr,SEQUENCE(,cr),rl,ROWS(l),sl,SEQUENCE(rl),rr,ROWS(r),sr,SEQUENCE(rr),ckr,COLUMNS(kr),
       a,INDEX(l,sl,kl),b,INDEX(r,sr,kr),ta,ATEXTJOIN(a,,,d),tb,ATEXTJOIN(b,,,d),x,XMATCH(ta,tb),xn,ISNUMBER(x),ia,FILTER(sl,xn,t),ib,FILTER(x,xn),
       al,INDEX(l,ia,ql),ar,ARRANGE(INDEX(r,ib,qr),kr),
       ml,OR(ISNA(XMATCH(kl,ql))),mr,OR(ISNA(XMATCH(kr,qr))),
       IFS(OR(ml,mr),"check keys",ia=t,t,TRUE,APPEND2H(al,ar,ckr+1))
    )
)
LAMBDA 7.0.xlsx
ABCDEFGHIJKLMNOPQRSTUVWX
1PQ name: Inner Join (And logical test)=AIJOIN(A2:C14,E2:H10,{3,2},{2,4})array 1array 2find common names in both arrays
2UnitsColorProductCodeProductPriceColorUnitsColorProductCodePriceSol MarroquinRaven Beatty=AIJOIN(P2:P13,S2:S13,,)
348RedQuadCR-rCarlota26Red48RedQuadQD-r43Kiera McfallRoxanna MercierRaven Beatty
4156BlueQuadKK-bKiki13Blue156BlueQuadQD-b41Raven BeattyFanny DenningWei Lockwood
5168RedQuadQD-rQuad43Red168RedQuadQD-r43Elinore DeesLesha NoblesAngelita Packer
6132BlueCarlotaSH-rSunshine19Red108RedSunshineSH-r19Wei LockwoodWei LockwoodBeaulah Wenger
772BlueCarlotaCR-gCarlota24Green128BlueQuadQD-b41Donald EldridgeGertrudis FitzpatrickMalvina Hamer
8108RedSunshineQD-bQuad41Blue96RedCarlotaCR-r26Claudio BeamAngelita Packer
9128BlueQuadSH-bSunshine18Blue60RedSunshineSH-r19Angelita PackerBeaulah Wengerif we invert order of arrays in formula
1096RedCarlotaKK-rKiki20Red24BlueSunshineSH-b18Reyna LukeMalvina Hamerwe get the same result
1160RedSunshine24BlueQuadQD-b41Beaulah WengerBernita Crutcher=AIJOIN(S2:S13,P2:P13,,)
1224BlueSunshineinner join left to right(dups in left array)Malvina HamerShiela AnayaRaven Beatty
13120BlueCarlotaObs:If there are duplicates of keys Vivan KeeneyYolonda ArmsteadWei Lockwood
1424BlueQuadon left array, all will be shownAngelita Packer
15error debug.=ARRANGE(J2#,{3,4,2,5})=APIVOT(J17:N25,1,3,5,1)countsBeaulah Wenger
16=AIJOIN(A3:C14,E3:H10,4,2)ProductCodeColorPriceUnits(1\3) 5 vf=1BlueRedGrand TotalMalvina Hamer
17check keysQuadQD-rRed4348Carlota011
18QuadQD-bBlue41156Quad325
19(key left column out of range)QuadQD-rRed43168Sunshine123
20SunshineSH-rRed19108Grand Total459
21=AIJOIN(A3:C14,E3:H10,3,4)QuadQD-bBlue41128
22not foundCarlotaCR-rRed2696=APIVOT(J17:N25,1,3,5,)sum units
23SunshineSH-rRed1960(1\3) 5 vf=0BlueRedGrand Total
24(keys in range butSunshineSH-bBlue1824Carlota09696
25no common data found)QuadQD-bBlue4124Quad308216524
26Sunshine24168192
27=AIJOIN(E2:H10,A2:C14,{2,4},{3,2})Grand Total332480812
28CodeProductPriceColorUnits
29CR-rCarlota26Red96other functions used on minisheet
30QD-rQuad43Red48ARRANGE
31SH-rSunshine19Red108APIVOT
32QD-bQuad41Blue156
33SH-bSunshine18Blue24
34inner join right to left(dups in left array)
35Obs:If there are duplicates of keys
36only first occurrence is shown
AIJOIN post
Cell Formulas
RangeFormula
J1,J27,P22,E21,E16,P15,J15,U11,U2J1=FORMULATEXT(J2)
J2:N11J2=AIJOIN(A2:C14,E2:H10,{3,2},{2,4})
U3:U7U3=AIJOIN(P2:P13,S2:S13,,)
U12:U16U12=AIJOIN(S2:S13,P2:P13,,)
J16:N25J16=ARRANGE(J2#,{3,4,2,5})
P16:S20P16=APIVOT(J17:N25,1,3,5,1)
E17E17=AIJOIN(A3:C14,E3:H10,4,2)
E22E22=AIJOIN(A3:C14,E3:H10,3,4)
P23:S27P23=APIVOT(J17:N25,1,3,5,)
J28:N33J28=AIJOIN(E2:H10,A2:C14,{2,4},{3,2})
Dynamic array formulas.
 
Upvote 0
Here are the general notes addendum of the 6 Power Querry scenarios for merging/joining tables.
4 functions will cover all 6 scenarios, for any arrays not only tables, no PQ or refresh needed: AIJOIN, ALMERGE, AMERGE, AJOIN
1. Inner Join (AND logical test) , our function AIJOIN
2. Left Anti (Only in left array), our function ALMERGE
3. Left Outer (Classic Lookup in right array), our function AMERGE (most common)
4. Right Anti (Only in right array), we can use ALMERGE inverting the order of arrays in the formula
5. Right Outer (Classic Lookup in left array), we can use AMERGE inverting the order of arrays in the formula
6. Full Outer (OR logical text), our function AJOIN
The "links" for this types of joining/merging are called "keys", primary (unique) or foreign keys. They represents common column or multiple columns found in both arrays (they share the same type of data of the respective columns and should have same dimension, in most of the cases).
The functions can handle also dups of keys along with unique keys, and for that reason we can have different outcomes if we apply same functions from left to right or right to left. Plenty of examples on minisheets to reveal this behavior.
Attached picture, courtesy of Mike Girvin ExcelIsFun together with some of the sample data found on these posts.
PQ join merge.png
 
2nd addendum: All the formulas except AJOIN, can handle multiple columns "keys". In most cases they should have the same dimension. Anyhow, the functions can handle dif dimension "keys", but only if we are positive that their join values are similar and can be matched. As an example, an array can have as key, 2 sep columns, first names and last names, and the other array has only a single column key for first names and last names joined with a delimiter in between. The default delimiter used in my formula is "|", did not used it as a separate argument, but can be changed inside formulas. It is variable "d" defined after LET. Or we can use our text manipulation formulas to change any delimiter with "|". It has powerful versatility but has to be handled with care.
LAMBDA 7.0.xlsx
ABCDEFGHIJKLMNOPQRSTUVW
1different keys dimensions scenarioarray 1array 2Left Anti (Only in left array)Right Anti (Only in right array)
2list 1 samplelist 2 sample,dif delimitersFirst NameLast NameUnitsNamePrice=ALMERGE(F3:H14,K3:L14,{1,2},)=ALMERGE(K3:L14,F3:H14,,{1,2})
3Sol MarroquinRaven,BeattySolMarroquin29Raven|Beatty123First NameLast NameUnitsNamePrice
4Kiera McfallRoxanna MercierKieraMcfall14Roxanna|Mercier213SolMarroquin29Roxanna|Mercier213
5Raven BeattyFanny,DenningRavenBeatty23Fanny|Denning323KieraMcfall14Fanny|Denning323
6Elinore DeesLesha NoblesElinoreDees15Lesha|Nobles211ElinoreDees15Lesha|Nobles211
7Wei LockwoodWei/LockwoodWeiLockwood19Wei|Lockwood124DonaldEldridge24Gertrudis|Fitzpatrick245
8Donald EldridgeGertrudis FitzpatrickDonaldEldridge24Gertrudis|Fitzpatrick245ClaudioBeam34Bernita|Crutcher100
9Claudio BeamAngelita PackerClaudioBeam34Angelita|Packer267ReynaLuke7Shiela|Anaya110
10Angelita PackerBeaulah WengerAngelitaPacker23Beaulah|Wenger213VivanKeeney14Yolonda|Armstead423
11Reyna LukeMalvina HamerReynaLuke7Malvina|Hamer321
12Beaulah WengerBernita\CrutcherBeaulahWenger8Bernita|Crutcher100Inner Join (And logical test)Inner Join (And logical test)
13Malvina HamerShiela AnayaMalvinaHamer11Shiela|Anaya110=AIJOIN(F3:H14,K3:L14,{1,2},)=AIJOIN(K3:L14,F3:H14,,{1,2})
14Vivan KeeneyYolonda ArmsteadVivanKeeney14Yolonda|Armstead423First NameLast NameUnitsPriceNamePriceUnits
15RavenBeatty23123Raven|Beatty12323
16functionsLeft Outter (Classic lookup in right array)Right Outter (Classic lookup in left array)WeiLockwood19124Wei|Lockwood12419
17used in minisheetformula to change all delimiters=AMERGE(F3:H14,K3:L14,{1,2},)=AMERGE(K3:L14,F3:H14,1,{1,2})AngelitaPacker23267Angelita|Packer26723
18AREMOVE=AREMOVE(C3:C14,T_CHARS(,,", /\"),"|")NameLast NameUnitsPriceNamePriceUnitsBeaulahWenger8213Beaulah|Wenger2138
19T_CHARSRaven|BeattySolMarroquin29Raven|Beatty12323MalvinaHamer11321Malvina|Hamer32111
20AMERGERoxanna|MercierKieraMcfall14Roxanna|Mercier213Inner Join has the same outcome in different structures
21ALMERGEFanny|DenningRavenBeatty23123Fanny|Denning323
22AIJOINLesha|NoblesElinoreDees15Lesha|Nobles211Due to the way the functions are constructed, AJOIN can not be used
23AJOINWei|LockwoodWeiLockwood19124Wei|Lockwood12419with different keys dimensions
24Gertrudis|FitzpatrickDonaldEldridge24Gertrudis|Fitzpatrick245=AJOIN(F3:H14,K3:L14,{1,2},1)=AJOIN(K3:L14,F3:H14,,{1,2})
25Angelita|PackerClaudioBeam34Angelita|Packer26723First NameLast NameUnitsPriceNamePriceUnits
26Beaulah|WengerAngelitaPacker23267Beaulah|Wenger2138SolMarroquin29Raven|Beatty12323
27Malvina|HamerReynaLuke7Malvina|Hamer32111KieraMcfall14Roxanna|Mercier213
28Bernita|CrutcherBeaulahWenger8213Bernita|Crutcher100RavenBeatty23123Fanny|Denning323
29Shiela|AnayaMalvinaHamer11321Shiela|Anaya110ElinoreDees15Lesha|Nobles211
30Yolonda|ArmsteadVivanKeeney14Yolonda|Armstead423WeiLockwood19124Wei|Lockwood12419
31DonaldEldridge24Gertrudis|Fitzpatrick245
32ClaudioBeam34Angelita|Packer26723
33AngelitaPacker23267Beaulah|Wenger2138
34ReynaLuke7Malvina|Hamer32111
35BeaulahWenger8213Bernita|Crutcher100
36MalvinaHamer11321Shiela|Anaya110
37VivanKeeney14Yolonda|Armstead423
38#VALUE!#VALUE!#VALUE!213Sol29
39#VALUE!#VALUE!#VALUE!323Kiera14
40#VALUE!#VALUE!#VALUE!211Elinore15
41#VALUE!#VALUE!#VALUE!245Donald24
42#VALUE!#VALUE!#VALUE!100Claudio34
43#VALUE!#VALUE!#VALUE!110Reyna7
44#VALUE!#VALUE!#VALUE!423Vivan14
45
Key dif dim post
Cell Formulas
RangeFormula
O2,T24,O24,K17,F17,T13,O13,T2O2=FORMULATEXT(O4)
F3:G14F3=ASPLIT(A3:A14," ")
K3:K14K3=AREMOVE(C3:C14,T_CHARS(,,", /\"),"|")
O4:Q10O4=ALMERGE(F3:H14,K3:L14,{1,2},)
T4:U10T4=ALMERGE(K3:L14,F3:H14,,{1,2})
O15:R19O15=AIJOIN(F3:H14,K3:L14,{1,2},)
T15:V19T15=AIJOIN(K3:L14,F3:H14,,{1,2})
C18C18=FORMULATEXT(C19)
C19:C30C19=AREMOVE(C3:C14,T_CHARS(,,", /\"),"|")
F19:I30F19=AMERGE(F3:H14,K3:L14,{1,2},)
K19:M30K19=AMERGE(K3:L14,F3:H14,1,{1,2})
O26:R44O26=AJOIN(F3:H14,K3:L14,{1,2},1)
T26:V44T26=AJOIN(K3:L14,F3:H14,,{1,2})
Dynamic array formulas.
 

Forum statistics

Threads
1,224,836
Messages
6,181,252
Members
453,028
Latest member
letswriteafairytale

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