ALMERGE

=ALMERGE(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 Left Anti

Xlambda

Well-known Member
Joined
Mar 8, 2021
Messages
860
Office Version
  1. 365
Platform
  1. Windows
ALMERGE arrays Left Merge, same functionality as in Power Querry join/merge scenario called Left Anti. Calls ATEXTJOIN
Other functions used on minisheet ARRANGE , AIJOIN
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),
       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,NOT(xn),t),al,INDEX(l,ia,ql),
       ml,OR(ISNA(XMATCH(kl,ql))),mr,OR(ISNA(XMATCH(kr,qr))),
       IFS(OR(ml,mr),"check keys",ia=t,t,TRUE,al)
    )
)
LAMBDA 7.0.xlsx
ABCDEFGHIJKLMNOPQRSTU
1PQ name: Left Anti (Only in left array)array 1array 2find names only in left array
2UnitsColorProductCodeProductPriceColor=ALMERGE(A3:C14,E3:H10,{3,2},{2,4})Sol MarroquinRaven Beatty=ALMERGE(O2:O13,Q2:Q13,,)
348RedQuadCR-rCarlota26Red132BlueCarlotaKiera McfallRoxanna MercierSol Marroquin
4156BlueQuadKK-bKiki13Blue72BlueCarlotaRaven BeattyFanny DenningKiera Mcfall
5168RedQuadQD-rQuad43Red96RedGigiElinore DeesLesha NoblesElinore Dees
6132BlueCarlotaSH-rSunshine19Red120BlueCarlotaWei LockwoodWei LockwoodDonald Eldridge
772BlueCarlotaCR-gCarlota24Greenleft to rightDonald EldridgeGertrudis FitzpatrickClaudio Beam
8108RedSunshineQD-bQuad41Blue=ALMERGE(A3:C14,E3:H10,3,2)Claudio BeamAngelita PackerReyna Luke
9128BlueQuadSH-bSunshine18Blue96RedGigiAngelita PackerBeaulah WengerVivan Keeney
1096RedGigiKK-rKiki20RedReyna LukeMalvina Hamer(if we invert right and left arrays)
1160RedSunshineerror debug.Beaulah WengerBernita CrutcherPQ name: Right Anti (Only in right array)
1224BlueSunshine=ALMERGE(E3:H10,A3:C14,{2,4},{3,2})=ALMERGE(A3:C14,E3:H10,2,5)Malvina HamerShiela Anayafind names only in right array
13120BlueCarlotaCR-rCarlota26Redcheck keysVivan KeeneyYolonda Armstead=ALMERGE(Q2:Q13,O2:O13,,)
1424BlueQuadKK-bKiki13BlueRoxanna Mercier
15CR-gCarlota24Green(key right column out of range)Fanny Denning
16KK-rKiki20RedLesha Nobles
17right to leftGertrudis Fitzpatrick
18PQ name: Right Anti (Only in right array)=ALMERGE(A3:C14,E3:H10,2,4)Bernita Crutcher
19not foundShiela Anaya
20Yolonda Armstead
21(keys in range but
22no data only in left array)PQ name: Inner Join
23find common names in both arrays
24=ARRANGE(J3#,{3,2})=AIJOIN(O2:O13,Q2:Q13,,)
25CarlotaBlue132Raven Beatty
26CarlotaBlue72Wei Lockwood
27GigiRed96Angelita Packer
28CarlotaBlue120Beaulah Wenger
29Malvina Hamer
30other functions used on minisheet
31ARRANGE
32AIJOIN
ALMERGE post
Cell Formulas
RangeFormula
J2,S24,J24,J18,S13,E12,J12,J8,S2J2=FORMULATEXT(J3)
J3:L6J3=ALMERGE(A3:C14,E3:H10,{3,2},{2,4})
S3:S9S3=ALMERGE(O2:O13,Q2:Q13,,)
J9:L9J9=ALMERGE(A3:C14,E3:H10,3,2)
E13:H16E13=ALMERGE(E3:H10,A3:C14,{2,4},{3,2})
J13J13=ALMERGE(A3:C14,E3:H10,2,5)
S14:S20S14=ALMERGE(Q2:Q13,O2:O13,,)
J19J19=ALMERGE(A3:C14,E3:H10,2,4)
J25:L28J25=ARRANGE(J3#,{3,2})
S25:S29S25=AIJOIN(O2:O13,Q2:Q13,,)
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,223,604
Messages
6,173,320
Members
452,510
Latest member
RCan29

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