여러 시트의 데이터 요약
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
코딩 수준: 초급
기간: 5분
프로젝트 유형: 맞춤 함수
목표
- 솔루션의 기능을 이해합니다.
- 솔루션 내에서 Apps Script 서비스가 하는 역할을 이해합니다.
- 스크립트를 설정합니다.
- 스크립트를 실행합니다.
이 솔루션 정보
스프레드시트의 여러 시트에 유사한 정형 데이터(여러 팀원의 고객 지원 측정항목 등)가 있는 경우 이 커스텀 함수를 사용하면 각 시트의 요약을 만들 수 있습니다. 이 솔루션은 고객 지원 티켓에 초점을 맞추고 있지만 니즈에 따라 맞춤설정할 수 있습니다.

작동 방식
getSheetsData()
라는 맞춤 함수는 스프레드시트의 각 시트에서 시트의 상태 열을 기반으로 데이터를 요약합니다. 스크립트는 ReadMe 및 Summary 시트와 같이 집계에 포함하면 안 되는 시트를 무시합니다.
Apps Script 서비스
이 솔루션은 다음 서비스를 사용합니다.
- 스프레드시트 서비스: 요약해야 하는 시트를 가져오고 지정된 문자열과 일치하는 항목 수를 계산합니다. 그런 다음 스크립트는 스프레드시트에서 맞춤 함수가 호출된 위치와 관련된 범위에 계산된 정보를 추가합니다.
기본 요건
이 샘플을 사용하려면 다음 기본 요건이 필요합니다.
- Google 계정 (Google Workspace 계정의 경우 관리자 승인이 필요할 수 있음)
- 인터넷에 액세스할 수 있는 웹브라우저
스크립트 설정
아래 버튼을 클릭하여 스프레드시트 데이터 요약
맞춤 함수 스프레드시트의 사본을 만듭니다. 이 솔루션의 Apps Script 프로젝트는 스프레드시트에 첨부되어 있습니다.
사본 만들기
스크립트 실행
- 복사한 스프레드시트에서 요약 시트로 이동합니다.
A4
셀을 클릭합니다. getSheetsData()
함수는 이 셀에 있습니다.
- 소유자 시트 중 하나로 이동하여 시트의 데이터를 업데이트하거나 추가합니다. 시도해 볼 수 있는 몇 가지 작업은 다음과 같습니다.
- 샘플 티켓 정보가 포함된 새 행을 추가합니다.
- 상태 열에서 기존 티켓의 상태를 변경합니다.
- 상태 열의 위치를 변경합니다. 예를 들어 Owner1 시트에서 Status 열을 C열에서 D열로 이동합니다.
- 요약 시트로 이동하여
A4
셀에서 getSheetsData()
가 만든 업데이트된 요약 표를 검토합니다. 10번째 행의 체크박스를 선택하여 맞춤 함수의 캐시된 결과를 새로고침해야 할 수 있습니다.
Google은 성능을 최적화하기 위해 맞춤 함수를 캐시합니다.
- 행을 추가하거나 업데이트한 경우 스크립트에서 티켓 및 상태 수를 업데이트합니다.
- 상태 열의 위치를 이동한 경우 스크립트는 새 열 색인으로 의도한 대로 작동합니다.
코드 검토
이 솔루션의 Apps Script 코드를 검토하려면 아래의 소스 코드 보기를 클릭하세요.
수정사항
필요에 따라 맞춤 함수를 원하는 만큼 수정할 수 있습니다. 아래는 맞춤 함수 결과를 수동으로 새로고침하는 선택적 추가 기능입니다.
캐시된 결과 새로고침
내장 함수와 달리 Google은 성능을 최적화하기 위해 사용자 정의 함수를 캐시합니다. 즉, 맞춤 함수 내에서 계산되는 값과 같은 항목을 변경해도 즉시 업데이트가 강제되지 않을 수 있습니다. 함수 결과를 수동으로 새로고침하려면 다음 단계를 따르세요.
- 삽입
> 체크박스를 클릭하여 빈 셀에 체크박스를 추가합니다.
- 체크박스가 있는 셀을 맞춤 함수의 매개변수로 추가합니다(예:
getSheetsData(B11)
).
- 체크박스를 선택하거나 선택 해제하여 맞춤 함수 결과를 새로고침합니다.
참여자
이 샘플은 Google Developer Expert의 도움을 받아 Google에서 유지관리합니다.
다음 단계
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-31(UTC)
[null,null,["최종 업데이트: 2025-08-31(UTC)"],[[["\u003cp\u003eThis custom function, \u003ccode\u003egetSheetsData()\u003c/code\u003e, summarizes data from multiple sheets in a spreadsheet, excluding "ReadMe" and "Summary" sheets, based on the "Status" column.\u003c/p\u003e\n"],["\u003cp\u003eThe function utilizes the Spreadsheet service to retrieve sheet data, count items matching specific statuses, and display the summarized information in a table.\u003c/p\u003e\n"],["\u003cp\u003eUsers need a Google Account and a web browser to use this solution; to set it up, they should make a copy of the provided spreadsheet containing the script.\u003c/p\u003e\n"],["\u003cp\u003eTo run the script, users navigate to the "Summary" sheet, observe the function output, modify data in other sheets, and check for updates on the "Summary" sheet, optionally refreshing the cache if necessary.\u003c/p\u003e\n"]]],["The custom function `getSheetsData()` summarizes data from multiple sheets in a spreadsheet, excluding \"ReadMe\" and \"Summary\" sheets. It analyzes each sheet's \"Status\" column, counts tasks based on status (e.g., Complete, In-Progress), and totals all tasks per sheet. The script uses the Spreadsheet service to get sheet data and then adds the calculated information in a summary format to the location in the spreadsheet where the custom function is entered. It is designed for sheets with similarly structured data.\n"],null,["# Summarize data from multiple sheets\n\n**Coding level** : Beginner \n\n**Duration** : 5 minutes \n\n**Project type** : [Custom function](/apps-script/guides/sheets/functions)\n\nObjectives\n----------\n\n- Understand what the solution does.\n- Understand what the Apps Script services do within the solution.\n- Set up the script.\n- Run the script.\n\nAbout this solution\n-------------------\n\nIf you have similarly structured data on multiple sheets in a spreadsheet, such\nas customer support metrics for team members, you can use this custom function\nto create a summary of each sheet. This solution focuses on customer support\ntickets, but you can customize it to fit your needs.\n\n### How it works\n\nThe custom function, called `getSheetsData()`, summarizes data from each sheet\nin the spreadsheet based on a sheet's **Status** column. The script ignores\nsheets that shouldn't be included in the aggregation, such as the **ReadMe** and\n**Summary** sheets.\n\n### Apps Script services\n\nThis solution uses the following service:\n\n- [Spreadsheet service](/apps-script/reference/spreadsheet)--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.\n\nPrerequisites\n-------------\n\nTo use this sample, you need the following prerequisites:\n\n- A Google Account (Google Workspace accounts might require administrator approval).\n- A web browser with access to the internet.\n\nSet up the script\n-----------------\n\nClick the button below to make a copy of the **Summarize spreadsheet data\ncustom function** spreadsheet. The Apps Script project for\nthis solution is attached to the spreadsheet.\n\n[Make a copy](https://docs.google.com/spreadsheets/d/1ZyhrTm9q98oOWzKgD6OVb31Yc38ODEHINOOjgVwQpCg/copy)\n\nRun the script\n--------------\n\n1. In your copied spreadsheet, go to the **Summary** sheet.\n2. Click cell `A4`. The `getSheetsData()` function is in this cell.\n3. Go to one of the owner sheets and update or add data to the sheet. Some actions you can try include the following:\n - Add a new row with sample ticket information.\n - In the **Status** column, change the status of an existing ticket.\n - Change the position of the **Status** column. For example, in the **Owner1** sheet, move the **Status** column from column C to column D.\n4. Go to the **Summary** sheet and review the updated summary table that `getSheetsData()` created from cell `A4`. You might need to check the checkbox in row 10 to [refresh the cached results](#cache) of the custom function. Google caches custom functions to optimize performance.\n - If you added or updated rows, the script updates the ticket and status counts.\n - If you moved the position of the **Status** column, the script still works as intended with the new column index.\n\nReview the code\n---------------\n\nTo review the Apps Script code for this solution, click **View source code**\nbelow: \n\n#### View source code\n\n### Code.gs\n\n\u003cbr /\u003e\n\nsolutions/custom-functions/summarize-sheets-data/Code.js \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/solutions/custom-functions/summarize-sheets-data/Code.js) \n\n```javascript\n// To learn how to use this script, refer to the documentation:\n// https://developers.google.com/apps-script/samples/custom-functions/summarize-sheets-data\n\n/*\nCopyright 2022 Google LLC\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n https://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\n/**\n * Gets summary data from other sheets. The sheets you want to summarize must have columns with headers that match the names of the columns this function summarizes data from.\n * \n * @return {string} Summary data from other sheets.\n * @customfunction\n */\n\n// The following sheets are ignored. Add additional constants for other sheets that should be ignored.\nconst READ_ME_SHEET_NAME = \"ReadMe\";\nconst PM_SHEET_NAME = \"Summary\";\n\n/**\n * Reads data ranges for each sheet. Filters and counts based on 'Status' columns. To improve performance, the script uses arrays \n * until all summary data is gathered. Then the script writes the summary array starting at the cell of the custom function.\n */\nfunction getSheetsData() {\n let ss = SpreadsheetApp.getActiveSpreadsheet();\n let sheets = ss.getSheets();\n let outputArr = [];\n\n // For each sheet, summarizes the data and pushes to a temporary array.\n for (let s in sheets) {\n // Gets sheet name.\n let sheetNm = sheets[s].getName();\n // Skips ReadMe and Summary sheets.\n if (sheetNm === READ_ME_SHEET_NAME || sheetNm === PM_SHEET_NAME) { continue; }\n // Gets sheets data.\n let values = sheets[s].getDataRange().getValues();\n // Gets the first row of the sheet which is the header row.\n let headerRowValues = values[0];\n // Finds the columns with the heading names 'Owner Name' and 'Status' and gets the index value of each.\n // Using 'indexOf()' to get the position of each column prevents the script from breaking if the columns change positions in a sheet.\n let columnOwner = headerRowValues.indexOf(\"Owner Name\");\n let columnStatus = headerRowValues.indexOf(\"Status\");\n // Removes header row.\n values.splice(0,1);\n // Gets the 'Owner Name' column value by retrieving the first data row in the array.\n let owner = values[0][columnOwner];\n // Counts the total number of tasks.\n let taskCnt = values.length;\n // Counts the number of tasks that have the 'Complete' status.\n // If the options you want to count in your spreadsheet differ, update the strings below to match the text of each option.\n // To add more options, copy the line below and update the string to the new text.\n let completeCnt = filterByPosition(values,'Complete', columnStatus).length;\n // Counts the number of tasks that have the 'In-Progress' status.\n let inProgressCnt = filterByPosition(values,'In-Progress', columnStatus).length;\n // Counts the number of tasks that have the 'Scheduled' status.\n let scheduledCnt = filterByPosition(values,'Scheduled', columnStatus).length;\n // Counts the number of tasks that have the 'Overdue' status.\n let overdueCnt = filterByPosition(values,'Overdue', columnStatus).length;\n // Builds the output array.\n outputArr.push([owner,taskCnt,completeCnt,inProgressCnt,scheduledCnt,overdueCnt,sheetNm]);\n }\n // Writes the output array.\n return outputArr;\n}\n\n/**\n * Below is a helper function that filters a 2-dimenstional array.\n */\nfunction filterByPosition(array, find, position) {\n return array.filter(innerArray =\u003e innerArray[position] === find);\n}\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nModifications\n-------------\n\nYou can edit the custom function as much as you'd like to fit your needs. Below\nis an optional addition to manually refresh custom function results. \n\n#### Refresh cached results\n\n\nUnlike built-in functions, Google caches custom functions to optimize\nperformance. This means that if you change something within your custom\nfunction, such as a value that's being calculated, it might not immediately\nforce an update. To refresh the function result manually, take the following\nsteps:\n\n1. Add a checkbox to an empty cell by clicking **Insert** \\\u003e **Checkbox**.\n2. Add the cell that has the checkbox as a parameter of the custom function, for example, `getSheetsData(B11)`.\n3. Check or uncheck the checkbox to refresh the custom function results.\n\nContributors\n------------\n\nThis sample is maintained by Google with the help of Google Developer Experts.\n\nNext steps\n----------\n\n- [Custom functions in Google Sheets](/apps-script/guides/sheets/functions)\n- [Extending Google Sheets](/apps-script/guides/sheets)"]]