Search code examples
google-sheetsgoogle-sheets-formulaarray-formulasgoogle-sheets-queryimportrange

adding sheet name when importing multiple sheets using importrange


I am importing multiple sheets into one using importrange and query function. Each sheet belongs to a different person. Is it possible to show which person the imported row belongs to?

I have:

=QUERY({importrange({"https://docs.google.com/spreadsheets/d/dsafdsf33/edit#gid=0"},"Original!A4:V");importrange("https://docs.google.com/spreadsheets/d/2sdfsad34543/edit#gid=0","Original!A4:V")},"SELECT Col2,Col5,Col4,Col7,Col9,Col12 Where Col8='AU'")

This is importing data from Bob and Steve. I would like to have the row (first column maybe) to say whether the row is being imported from Bob or Steve. Is this possible?


Solution

  • without scripts it could be only hardcoded like this:

    =ARRAYFORMULA(QUERY({
     {IMPORTRANGE("abc", "Original!A4:V"), IMPORTRANGE("abc", "Original!Z4:Z")&"Bob"}; 
     {IMPORTRANGE("xyz", "Original!A4:V"), IMPORTRANGE("xyz", "Original!Z4:Z")&"Steve"}},
     "select Col2,Col5,Col4,Col7,Col9,Col12,Col19
      where Col8='AU'"))
    

    where Z4:Z range is an empty column