0

I have many spreadsheets where data will be added manually and which are all identical. Let's call these UserInputSpreadsheets.

Inside each user spreadsheet are tabs with data which are also identical.

Let's call these tabs Data Input Sheets.

ALl DataInputSheets are identical.

Seach UserSpreadsheet has 1 compilation tab, which compiles all the data in the DataInputSheets. Let's call them UserSpreadsheetCompilationTabs

Here's an example

User Input Spreadsheet 1

fig.1
DataInputSheet 1
date      | name | value
-----------------------
1/12/2022 | Foo  | bar
1/13/2022 | Baz  | Quox

fig.1
DataInputSheet 2
date      | name | value
-----------------------
1/12/2022 | Burr | Bazz
1/13/2022 | Butts| Bums

UserSpreadsheetCompilationTab1 

fig.3
date      | name | value
-----------------------
1/12/2022 | Foo  | bar
1/13/2022 | Baz  | Quox
1/12/2022 | Burr | Bazz
1/13/2022 | Butts| Bums

Now imagine there are 10 of these Spreadsheets that exist and all are going to be compiled into a MasterSpreadsheet.

Here is what the MasterSpreadsheetCompilationTab should look like if we have 2 spreadsheets, a 2nd that you cannot see, and the first one included using the sample data above.

fig.4
date      | name | value
-----------------------
1/12/2022 | Foo  | bar
1/13/2022 | Baz  | Quox
1/12/2022 | Burr | Bazz
1/13/2022 | Butts| Bums
1/15/2022 | Grr  | Arr

However, the number of UserInputSpreadsheets is a variable quantity and will definitely adjust over time. So I need the MasterSpreadsheetCompilationTab to be able to adjust its output based on this.

Therefore I created a manifest that lists the URLs of the UserInputSpreadsheets. Let's call it the Manifest

It looks like this:

fig.5
Slots | User name | UserInputSpreadsheetURL
--------------------------------------
1     | Nickypoo  | https://agooglesheeturl...
2     | Bennyboo  | https://agooglesheeturl...
3     | Hoopadoo  | https://agooglesheeturl...
4     | -         | -
5     | -         | - 

The MasterSpreadsheetCompilationTab needs to look at this Manifest and only display data that has a URL listed on this Manifest tab.

I think I'm pretty close with this function:

=reduce(
   importrange(Manifest!B3, "Compiled!A2:AE"), 
   filter(Manifest!B4:B12, isblank(Manifest!B4:B12)=false), 
   lambda(array, url, {
      array; query(importrange(url, "Compiled!A2:AE"), "select * where Col1 is not null")}))

However, it is only showing the first set of data in the first argument of the reduce function.

Essentially the MasterSpreadsheetCompilationTab looks like this if I use the sample data from above:

fig.6
date      | name | value
-----------------------
1/12/2022 | Foo  | bar
1/13/2022 | Baz  | Quox

I need it to look like fig 4.

3
  • 1
    Welcome to Web Applications Stack Exchange. Please show an example of the source data using a table together with a table that shows your manually entered desired results. You can simplify the scenario to just two or three columns. Also consider sharing a publicly editable sample spreadsheet. There is a blank sheet maker that lets you share safely. Commented Dec 5, 2022 at 21:31
  • Thnak you! I've heavily editing the question to use tables as you pointed out.
    – Nick Res
    Commented Dec 9, 2022 at 21:37
  • 1
    Consider sharing a publicly editable sample spreadsheet where the issue can be reproduced. There is a blank sheet maker that lets you share safely. Commented Dec 10, 2022 at 18:58

1 Answer 1

1

Use reduce() to merge several multi-row arrays into one taller array, like this:

=reduce( 
  importrange(C3, "Compiled!A1:AE1"), filter(C3:C14, B3:B14), 
  lambda( 
    result, url, 
    { 
      result; 
      query( 
        importrange(url, "Compiled!A2:AE"), 
        "where Col1 is not null", 0 
      ) 
    } 
  ) 
)
7
  • is the first argument supposed to be the starting array to be stacked by other arrays?
    – Nick Res
    Commented Dec 9, 2022 at 18:25
  • Yes. See reduce(). Commented Dec 9, 2022 at 18:30
  • Thank you! This function has me very close. The challenge I'm seeing is that I cannot push or append the newly queried array into the reduce accumulated array ("result").
    – Nick Res
    Commented Dec 9, 2022 at 20:50
  • Ohh, I see that the first argument in your reduce function includes the first result, and then the rest should build on that result. I was trying to append to an empty array to account for the possibility that there would be no data to begin with. But let's assume at least 1 source will work and it will be the first. The issue I see now is that only the base dataset is shown and not the data processed in the lambda.
    – Nick Res
    Commented Dec 9, 2022 at 21:06
  • 1
    Google Sheet formulas do not have a concept of a totally empty array. It is usually easiest to start with a single header row that lists column names, or a row that contains blanks (but has as many columns as the data.) It is unclear how the answer fails to meet your requirements. Please clarify. Commented Dec 9, 2022 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.