Search code examples
arraysregexgoogle-sheetsgoogle-sheets-formulagoogle-query-language

Google Sheets (Formula or GAScript) - Combine 2 sheets with unique columns into a single sheet


The Problem

I am trying to combine Sheet1 & Sheet2 into Sheet3 sorted by timestamp, but I am unable to adjust the columns so they match between both datasets. Is this even possible with using formulas, or is my only option Google App Scripts?

My Attempt

=query({Sheet1!A2:F;Sheet2!A2:F},"WHERE Col1 is not null ORDER BY Col1")

I have also tried other methods using helper columns, but that did not work very well either.

Spreadsheet:

https://docs.google.com/spreadsheets/d/1w1RIygC4GodoIvzBGKbx5P_GwSqBMPJ6AkL8Dl5ZLOU/edit?usp=sharing

Sheet1

Timestamp First Name Email Address Phone Number Comments
3/15/2022 8:12:00 Jed JedRigby@ 123 St (778) 913-4767 Comment A
3/15/2022 9:23:00 Elle-May Elle-MayMcdermott@ 124 St (660) 632-5480 Comment B
3/15/2022 10:11:00 Junayd JunaydDavis@ 125 St (774) 516-6738 Comment C
3/19/2022 19:55:04 Caleb CalebMaddox@ 128 St (624) 540-7406 Comment D
3/19/2022 22:17:04 Misbah MisbahHowarth@ 129 St (890) 436-0537 Comment E

Sheet2

Timestamp First Name Last Name Email Address
3/15/2022 13:37:00 Jody English JodyEnglish@ 126 St
3/19/2022 17:32:04 Samual Savage SamualSavage@ 127 St
3/22/2022 7:24:04 Bill Short BillShort@ 130 St
3/22/2022 9:51:04 Jevon Conner JevonConner@ 131 St
3/22/2022 12:33:04 Clementine Talley ClementineTalley@ 132 St

COMBINED (Sheet1 & Sheet2) - Expected Reults

Timestamp First Name Last Name Email Address Phone Number Comments
3/15/2022 8:12:00 Jed Rigby JedRigby@ 123 St (778) 913-4767 Comment A
3/15/2022 9:23:00 Elle-May Mcdermott Elle-MayMcdermott@ 124 St (660) 632-5480 Comment B
3/15/2022 10:11:00 Junayd Davis JunaydDavis@ 125 St (774) 516-6738 Comment C
3/15/2022 13:37:00 Jody English JodyEnglish@ 126 St (492) 298-3670
3/19/2022 17:32:04 Samual Savage SamualSavage@ 127 St (871) 816-6015
3/19/2022 19:55:04 Caleb Maddox CalebMaddox@ 128 St (624) 540-7406 Comment D
3/19/2022 22:17:04 Misbah Howarth MisbahHowarth@ 129 St (890) 436-0537 Comment E
3/22/2022 7:24:04 Bill Short BillShort@ 130 St (660) 632-5480
3/22/2022 9:51:04 Jevon Conner JevonConner@ 131 St (549) 806-8647
3/22/2022 12:33:04 Clementine Talley ClementineTalley@ 132 St (660) 632-5480

Solution

  • try:

    =ARRAYFORMULA(QUERY({QUERY({Sheet1!A2:F, REGEXEXTRACT(Sheet1!C2:C, Sheet1!B2:B&"(.*)@")}, 
     "select Col1,Col2,Col7,Col3,Col4,Col5,Col6");
     QUERY(Sheet2!A2:F, "select A,B,C,D,E,F,' ' label ' '''")}, 
     "where Col1 is not null order by Col1", ))
    

    enter image description here