diff --git a/src/helpers/pivot/spreadsheet_pivot/data_entry_spreadsheet_pivot.ts b/src/helpers/pivot/spreadsheet_pivot/data_entry_spreadsheet_pivot.ts index 50ec14bcee..429443e28f 100644 --- a/src/helpers/pivot/spreadsheet_pivot/data_entry_spreadsheet_pivot.ts +++ b/src/helpers/pivot/spreadsheet_pivot/data_entry_spreadsheet_pivot.ts @@ -21,8 +21,9 @@ export function dataEntriesToSpreadsheetPivotTable( dataEntries: DataEntries, definition: SpreadsheetPivotRuntimeDefinition ) { + const measureIds = definition.measures.filter((measure) => !measure.isHidden).map((m) => m.id); const columnsTree = dataEntriesToColumnsTree(dataEntries, definition.columns, 0); - computeWidthOfColumnsNodes(columnsTree, definition.measures.length); + computeWidthOfColumnsNodes(columnsTree, measureIds.length); const cols = columnsTreeToColumns(columnsTree, definition); const rows = dataEntriesToRows(dataEntries, 0, definition.rows, [], []); @@ -33,7 +34,6 @@ export function dataEntriesToSpreadsheetPivotTable( indent: 0, }); - const measureIds = definition.measures.filter((measure) => !measure.isHidden).map((m) => m.id); const fieldsType: Record = {}; for (const columns of definition.columns) { fieldsType[columns.fieldName] = columns.type; diff --git a/tests/pivots/spreadsheet_pivot/spreadsheet_pivot.test.ts b/tests/pivots/spreadsheet_pivot/spreadsheet_pivot.test.ts index 253555bab8..b3c375d9e3 100644 --- a/tests/pivots/spreadsheet_pivot/spreadsheet_pivot.test.ts +++ b/tests/pivots/spreadsheet_pivot/spreadsheet_pivot.test.ts @@ -2100,4 +2100,29 @@ describe("Spreadsheet arguments parsing", () => { ["Total", "", ""], ]); }); + + test("Column headers are correct when hiding a measure", () => { + // prettier-ignore + const grid = { + A1: "Price", B1: "Tax", C1: "Salesman", + A2: "10", B2: "2", C2: "Alice", + A3: "20", B3: "4", C3: "Bob", + A5: "=PIVOT(1)", + }; + const model = createModelFromGrid(grid); + addPivot(model, "A1:C3", { + rows: [], + columns: [{ fieldName: "Salesman" }], + measures: [ + { id: "Price:sum", fieldName: "Price", aggregator: "sum" }, + { id: "Tax:sum", fieldName: "Tax", aggregator: "sum", isHidden: true }, + ], + }); + // prettier-ignore + expect(getEvaluatedGrid(model, "A5:D7")).toEqual([ + ["(#1) Pivot", "Alice", "Bob", "Total"], + ["", "Price", "Price", "Price"], + ["Total", "10", "20", "30"], + ]); + }); });