AJOIN

=AJOIN(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 Full Outer

Xlambda

Well-known Member
Joined
Mar 8, 2021
Messages
860
Office Version
  1. 365
Platform
  1. Windows
AJOIN arrays Join, same functionality as in Power Querry join/merge scenario called Full Outer. Calls ALMERGE , AMERGE , APPEND2V
Excel Formula:
=LAMBDA(l,r,klf,krt,
    LET(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),
       al,ALMERGE(r,l,kr,kl),a,AMERGE(l,r,kl,kr),c,COLUMNS(a),s,SEQUENCE(,c),y,FILTER(qr,ISNA(XMATCH(qr,kr))),
       d,COLUMNS(l),x,XLOOKUP(s,kl,kr),z,IF(s<=d,x,INDEX(y,s-d)),v,INDEX(al,SEQUENCE(ROWS(al)),z),
       ml,OR(ISNA(XMATCH(kl,ql))),mr,OR(ISNA(XMATCH(kr,qr))),
       IF(OR(ml,mr),"check keys",APPEND2V(a,v,))
    )
)
LAMBDA 7.0.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXY
1PQ name: Full Outter (Left Outter+non matching in right array)PQ name: Full Outter (Righ Outter+non matching in left array)
2UnitsColorProductCodeProductPriceColor=AJOIN(A2:C14,E2:H10,{3,2},{2,4})=AJOIN(E2:H10,A2:C14,{2,4},{3,2})
348RedQuadCR-rCarlota26RedUnitsColorProductCodePriceCodeProductPriceColorUnitsarray 1array 2
4156BlueQuadKK-bKiki13Blue48RedQuadQD-r43CR-rCarlota26RedSol MarroquinRaven Beatty
5168RedQuadQD-rQuad43Red156BlueQuadQD-b41KK-bKiki13BlueKiera McfallRoxanna Mercier
6132BlueCarlotaSH-rSunshine19Red168RedQuadQD-r43QD-rQuad43Red48Raven BeattyFanny Denning
772BlueCarlotaCR-gCarlota24Green132BlueCarlotaSH-rSunshine19Red108Elinore DeesLesha Nobles
8108RedSunshineQD-bQuad41Blue72BlueCarlotaCR-gCarlota24GreenWei LockwoodWei Lockwood
9128BlueQuadSH-bSunshine18Blue108RedSunshineSH-r19QD-bQuad41Blue156Donald EldridgeGertrudis Fitzpatrick
1096RedGigiKK-rKiki20Red128BlueQuadQD-b41SH-bSunshine18Blue24Claudio BeamAngelita Packer
1160RedSunshine96RedGigiKK-rKiki20RedAngelita PackerBeaulah Wenger
1224BlueSunshine60RedSunshineSH-r19CarlotaBlue132Reyna LukeMalvina Hamer
13120BlueCarlota24BlueSunshineSH-b18CarlotaBlue72Beaulah WengerBernita Crutcher
1424BlueQuad120BlueCarlotaGigiRed96Malvina HamerShiela Anaya
1524BlueQuadQD-b41CarlotaBlue120Vivan KeeneyYolonda Armstead
16RedCarlotaCR-r26
17BlueKikiKK-b13when keys have no dups, same results both directions
18GreenCarlotaCR-g24=SORT(AJOIN(V4:V15,X4:X15,,))=SORT(AJOIN(X4:X15,V4:V15,,))
19RedKikiKK-r20Angelita PackerAngelita Packer
20Beaulah WengerBeaulah Wenger
21Bernita CrutcherBernita Crutcher
22Claudio BeamClaudio Beam
23Donald EldridgeDonald Eldridge
24Elinore DeesElinore Dees
25Fanny DenningFanny Denning
26Gertrudis FitzpatrickGertrudis Fitzpatrick
27Kiera McfallKiera Mcfall
28Lesha NoblesLesha Nobles
29Malvina HamerMalvina Hamer
30Raven BeattyRaven Beatty
31Reyna LukeReyna Luke
32Roxanna MercierRoxanna Mercier
33Shiela AnayaShiela Anaya
34Sol MarroquinSol Marroquin
35Vivan KeeneyVivan Keeney
36Wei LockwoodWei Lockwood
37Yolonda ArmsteadYolonda Armstead
38
AJOIN post
Cell Formulas
RangeFormula
J2,V18,X18,P2J2=FORMULATEXT(J3)
J3:N19J3=AJOIN(A2:C14,E2:H10,{3,2},{2,4})
P3:T15P3=AJOIN(E2:H10,A2:C14,{2,4},{3,2})
V19:V37V19=SORT(AJOIN(V4:V15,X4:X15,,))
X19:X37X19=SORT(AJOIN(X4:X15,V4:V15,,))
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.
View attachment 37624
 
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,251
Members
453,027
Latest member
Lost_in_spreadsheets

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