Home > Blockchain >  How to import data from multiple sheets into one sheet with BYROW and LAMBDA?
How to import data from multiple sheets into one sheet with BYROW and LAMBDA?

Time:10-28

I have a sheet with various tabs. Each tab has the same column header in A1 and similar data (same format) in column A. In "sheet2" I have a list of all the tab names in Column A. I wish to combine all the data for all tab's row A into "sheet2" in column B.

I have managed to get the desired result using... =ARRAYFORMULA({indirect(A1&"!A2:A"&COUNTA(indirect(A1&"!A:A")));indirect(A2&"!A2:A"&COUNTA(indirect(A2&"!A:A")))})

However, this only covers 2 tabs, and I have about 50 tabs to add, with more tabs added regularly.

So I wish to try and use a QUERY formula, which was recommended to me. I have run a few versions, see below, but the resulting output is 5 rows of

#VALUE!

BYROW and LAMBDA are new to me and I am uncertain on what I am doing wrong.

=QUERY(BYROW(A1:A5,LAMBDA(x, INDIRECT(x&"!A2:A6")))))

=ARRAYFORMULA({QUERY(BYROW(A1:A5,LAMBDA(x, INDIRECT(x&"!A2:A6"))))})

Below is 2 samples of the tabs where the data is stored, each tab is names after the Product Type, so EE and EX in this sample, and those same tab names are used in the third table (below).

Product Code
EE220123
EE190223
EE260323
EE030423
EE090423
EE170423
EE230423
EE010523
EE070523
EE150523
EE210523
EE280523
Product Code
EX040423
EX250423
EX160523
EX060623
EX270623
EX180723
EX080823
EX290823
EX190923
EX101023

This is my "sheet2"

Product Type
EE
EX
EJ
GB
GBIR

This is the sample sheet I am working on, columns F, G and H contain my recent attempt, it is Column H which I wish to get working. https://docs.google.com/spreadsheets/d/1gvOZ_GuZx6HOLHQ7WwyIlFHrAihoNXz2ysZkublh7Fs/edit#gid=1077440502

Expected Outcome table

Product Type Product Code
EE EE220123
EX EE190223
EJ EE260323
GB EE030423
GBIR EE090423
GBIR EE170423
EE230423
EE010523
EE070523
EE150523
EE210523
EE280523
EE290523
EX040423
EX250423
EX160523
EX060623
EX270623
EX180723
EX080823
EX290823
EX190923
EX101023
EJ240323
EJ070423
EJ210423
EJ050523
EJ190523
EJ020623
EJ160623
EJ300623
EJ140723
EJ280723
EJ110823
EJ250823
EJ080923
EJ220923
EJ061023
EJ201023
EJ221223
GB050323
GB020423
GB160423
GB300423
GB070523
GB140523
GB210523
GB280523
GB040623
GB110623
GB180623
GB250623
GB020723
GB090723
GB160723
GB230723
GB300723
GB060823
GB130823
GB200823
GB030923
GB100923
GB170923
GB240923
GB011023
GB151023
GB291023
GBIR080423
GBIR060523
GBIR200523
GBIR030623
GBIR170623
GBIR010723
GBIR150723
GBIR290723
GBIR120823
GBIR260823
GBIR090923
GBIR230923
GBIR071023
GBIR211023
GBIR221223

CodePudding user response:

Unlike BYROW, REDUCE supports nested arrays. You can use it to loop through A2:A6 of Sheet2 and add arrays from other sheets using array literals {;}

=REDUCE("Product Code", A2:A6, LAMBDA(a,c,{a;indirect(c&"!A2:A"&COUNTA(indirect(c&"!A:A")))}))
  • Related