Coding level: Beginner
Duration: 5 minutes
Project type: Custom function
Objectives
- Understand what the solution does.
- Understand what the Apps Script services do within the solution.
- Set up the script.
- Run the script.
About this solution
If you have similarly structured data on multiple sheets in a spreadsheet, such as customer support metrics for team members, you can use this custom function to create a summary of each sheet. This solution focuses on customer support tickets, but you can customize it to fit your needs.
How it works
The custom function, called getSheetsData()
, summarizes data from each sheet
in the spreadsheet based on a sheet's Status column. The script ignores
sheets that shouldn't be included in the aggregation, such as the ReadMe and
Summary sheets.
Apps Script services
This solution uses the following service:
- Spreadsheet service–Gets the sheets that need to be summarized and counts the number of items that match a specified string. Then, the script adds the calculated information to a range relative to where the custom function was called in the spreadsheet.
Prerequisites
To use this sample, you need the following prerequisites:
- A Google Account (Google Workspace accounts might require administrator approval).
- A web browser with access to the internet.
Set up the script
Click the button below to make a copy of the Summarize spreadsheet data
custom function spreadsheet. The Apps Script project for
this solution is attached to the spreadsheet.
Make a copy
Run the script
- In your copied spreadsheet, go to the Summary sheet.
- Click cell
A4
. ThegetSheetsData()
function is in this cell. - Go to one of the owner sheets and update or add data to the sheet. Some
actions you can try include the following:
- Add a new row with sample ticket information.
- In the Status column, change the status of an existing ticket.
- Change the position of the Status column. For example, in the Owner1 sheet, move the Status column from column C to column D.
- Go to the Summary sheet and review the updated summary table that
getSheetsData()
created from cellA4
. You might need to check the checkbox in row 10 to refresh the cached results of the custom function. Google caches custom functions to optimize performance.- If you added or updated rows, the script updates the ticket and status counts.
- If you moved the position of the Status column, the script still works as intended with the new column index.
Review the code
To review the Apps Script code for this solution, click View source code below:
View source code
Code.gs
Modifications
You can edit the custom function as much as you'd like to fit your needs. Below is an optional addition to manually refresh custom function results.
Refresh cached results
Unlike built-in functions, Google caches custom functions to optimize performance. This means that if you change something within your custom function, such as a value that's being calculated, it might not immediately force an update. To refresh the function result manually, take the following steps:
- Add a checkbox to an empty cell by clicking Insert > Checkbox.
- Add the cell that has the checkbox as a parameter of the custom function,
for example,
getSheetsData(B11)
. - Check or uncheck the checkbox to refresh the custom function results.
Contributors
This sample is maintained by Google with the help of Google Developer Experts.