diff --git a/src/plugins/ui_feature/format.ts b/src/plugins/ui_feature/format.ts index 7bfa2e424a..6056051054 100644 --- a/src/plugins/ui_feature/format.ts +++ b/src/plugins/ui_feature/format.ts @@ -11,6 +11,8 @@ import { CellValueType, Command, Format, + PivotTableCell, + PivotValueCell, Position, SetDecimalStep, UID, @@ -43,7 +45,7 @@ export class FormatPlugin extends UIPlugin { for (let row = zone.top; row <= zone.bottom; row++) { const position = { sheetId, col, row }; const pivotCell = this.getters.getPivotCellFromPosition(position); - if (pivotCell.type === "VALUE") { + if (this.isSpilledPivotValueFormula(position, pivotCell)) { measurePositions.push(position); const pivotId = this.getters.getPivotIdFromPosition(position) || ""; measuresByPivotId[pivotId] ??= new Set(); @@ -81,6 +83,13 @@ export class FormatPlugin extends UIPlugin { }); } + private isSpilledPivotValueFormula( + position: CellPosition, + pivotCell: PivotTableCell + ): pivotCell is PivotValueCell { + const cell = this.getters.getCell(position); + return pivotCell.type === "VALUE" && !cell?.isFormula; + } /** * This function allows to adjust the quantity of decimal places after a decimal * point on cells containing number value. It does this by changing the cells diff --git a/tests/formats/formatting_plugin.test.ts b/tests/formats/formatting_plugin.test.ts index bc4abe8a17..f5f51c2964 100644 --- a/tests/formats/formatting_plugin.test.ts +++ b/tests/formats/formatting_plugin.test.ts @@ -371,6 +371,22 @@ describe("pivot contextual formatting", () => { ["Total", "$1.00"], ]); }); + + test("format is not applied on the measure with fixed pivot values", () => { + // prettier-ignore + const grid = { + A1: "Customer", B1: "Price", C1: '=PIVOT.VALUE(1, "Price")', + A2: "Alice", B2: "10", + }; + const model = createModelFromGrid(grid); + addPivot(model, "A1:B2", { + rows: [{ fieldName: "Customer" }], + measures: [{ id: "Price", fieldName: "Price", aggregator: "count" }], + }); + setContextualFormat(model, "C1", "[$$]#,##0.00"); + expect(model.getters.getPivotCoreDefinition("1")?.measures[0].format).toBeUndefined(); + expect(getCell(model, "C1")?.format).toBe("[$$]#,##0.00"); + }); }); describe("formatting values (when change decimal)", () => {