메뉴
자유

피벗테이블 때문에 행 추가할 때마다 화가 나는데

12월 2일 조회 1,193
어떻게 자동화를 할 방법이 없을까요..ㅠ

스프레드시트에서 데이터 업데이트할 때마다 피벗테이블의 행이 늘어나서 아래에 있는 피벗테이블에 덮어씌워져서 매번 행을 새로이 추가해야 해서요.

미리 행을 여러 개 추가해두면 되긴 하는데, 이렇게 되면 데이터가 업데이트 되어 피벗테이블의 행이 늘어나기 전까지는 빈 행이 엄청 많아져서 밑에 있는 피벗테이블까지 스크롤을 너무 많이 내려야하는 문제가 생깁니다ㅠ

뭔가 앱스스크립트로 어떻게 해볼 수 있지 않을까 싶은데, 혹시 해결 방법을 아시는 분이 있을까요?

댓글 3

더블유에이 12월 4일
1시트 = 1데이터가 기본 규칙입니다.

앱스크립트로 피벗테이블 위치를 옮기는건 안될겁니다.

속성을 찾아보니 삭제만 있고 옮기는건 없네요

https://developers.google.com/apps-script/reference/spreadsheet/pivot-table?hl=ko

챗GPT에 물어보니 아래처럼 삭제 후 새로 만드는 것만 가능하다고 하는걸 보아.. 업데이트 후 피봇행 개수 - 기존 개수만큼 행을 추가하는 앱스크립트를 사용하면 될 듯 합니다

아래는 피봇테이블을 삭제하고 새로 추가하는 앱스크립트입니다 참고하세요
function movePivotTable() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1'); // Change 'Sheet1' to your sheet's name
  var pivotTableRange = sheet.getRange('A1'); // Change 'A1' to the top-left cell of your current pivot table
  var pivotTable = pivotTableRange.getPivotTables()[0];

  // Get data from the existing pivot table
  var sourceData = pivotTable.getSourceDataRange();
  var rows = pivotTable.getRowGroups();
  var columns = pivotTable.getColumnGroups();
  var values = pivotTable.getValues();

  // Define the new location for the pivot table
  var newLocation = sheet.getRange('E1'); // Change 'E1' to your new top-left cell for the pivot table

  // Create a new pivot table at the new location
  var newPivotTable = newLocation.createPivotTable(sourceData);

  // Add rows, columns, and values to the new pivot table based on the old pivot table
  rows.forEach(function(row) {
    newPivotTable.addRowGroup(row.getIndex());
  });

  columns.forEach(function(column) {
    newPivotTable.addColumnGroup(column.getIndex());
  });

  values.forEach(function(value) {
    newPivotTable.addPivotValue(value.getIndex(), value.getSummarizedBy());
  });

  // Remove the old pivot table
  pivotTableRange.clear(); // This clears the cells where the old pivot table was located
}

 
R
Rachel 12월 4일
오 감사합니다 :) 많은 도움 되었습니다!

 
아직 모르는 용어가 많네요.ㅎ

이야기 게시판의 최근 글

스크랩 완료