Combine two tables with different column headers

Here are two Excel "named ranges", which are Events1 and Events2 respectively. Starting from the 2nd row, both can be regarded as a table with column headers and some of their headers are same.

Column1

Column2

Column3

Column4

DATE

FIRST NAME

SURNAME

CODE

1/2/2024

John

Smith

3

1/2/2024

Lily

JJ

33

Column1

Column2

Column3


DATE

FULL NAME

CODE


1/3/2024

Peter Smith

2


1/3/2024

John Wilson

22








Task: Reference names of the two "named ranges" and combine the two tables; display a field that does not exist under the current range name as empty.

NAME

DATE

FIRST NAME

SURNAME

FULL NAME

CODE

Events1

1/2/2024

John

Smith


3

Events1

1/2/2024

Lily

JJ


33

Events2

1/3/2024



Peter Smith

2

Events2

1/3/2024



John Wilson

22

Use SPL XLL to do this:

=spl("=?1.to(3,).($[Events1]|~.m(1,2,3,0,4))|?2.to(3,).($[Events2]|~.m(1,0,0,2,3))",Events1,Events2)

Picture1png

to(3,) function gets members from the 3rd to the last. m()function gets multiple members according to their positions; 0 means null. ~ is the current member, and $[] represents a string.

Source:https://stackoverflow.com/questions/78253023/power-query-m-code-extract-a-list-of-tables-into-one-main-table-some-column