Problem: I am working with a Google Sheets file were the first tab is the 'raw export'. Data in this sheet looks basically like this:
Customer | Item | Cost |
---|---|---|
Amy | Shirt | 15.50 |
Amy | Pants | 20.00 |
Amy | Socks | 8.95 |
Bill | Shoes | 18.75 |
Bill | Socks | 5.99 |
Chris | Shirt | 13.65 |
Now, in the subsequent sheets I have a QUERY function that is grabbing all the results in the 'raw export' sheet relating to a particular customer. The customer is defined by the sheet name. So there is a tab for "Amy", "Bill", etc.
=QUERY(A:C, "SELECT * WHERE Col1 = '"&sheetName()&"'", 1)
The sheetName()
is a simple function I found from this source.
function sheetName() {
return SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName();
}
It works correctly for the initial sheet. The problem is the 'raw export' tab will keep receiving new data over time as most customers and purchases come in. So every time I duplicate the tab and change the tab name to add a new customer, the formula does not update. Thus, the query function does not show data for the new customer name referenced in the sheet name.
I am going to keep adding new tabs for new customers over time so it would be great if all I had to do was duplicate the tab and change the sheet name. Then the rest would populate accordingly.
Steps I Tried to Resolve: I tried setting up a Trigger that corresponds to any change, but it did not work.