Skip to content

Commit c75e9f3

Browse files
committed
[FIX] functions: ignore vectorized SUBTOTAL
SUBTOTAL should ignore SUBTOTAL values from a spilled formula A1: "1" A2: "1" A3: "=SUBTOTAL(9, A1:A2) + A1:A2" A5: "=SUBTOTAL(9, A4)" => A5 should be zero because the value in A4 comes from a SUBTOTAL formula and it should be ignored closes #7503 Task: 5261987 X-original-commit: c23e492 Signed-off-by: Rémi Rahir (rar) <rar@odoo.com> Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
1 parent 06263d9 commit c75e9f3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/o-spreadsheet-engine/src/functions/module_math.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ export const SUBTOTAL = {
14091409
if (!acceptHiddenCells && this.getters.isRowHiddenByUser(sheetId, row)) continue;
14101410

14111411
for (let col = left; col <= right; col++) {
1412-
const cell = this.getters.getCell({ sheetId, col, row });
1412+
const cell = this.getters.getCorrespondingFormulaCell({ sheetId, col, row });
14131413
if (!cell || !isSubtotalCell(cell)) {
14141414
evaluatedCellToKeep.push(this.getters.getEvaluatedCell({ sheetId, col, row }));
14151415
}

tests/functions/module_math.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3129,6 +3129,18 @@ describe("SUBTOTAL formula", () => {
31293129
expect(gridResult.A7).toBe(4);
31303130
});
31313131

3132+
test("SUBTOTAL ignores spilled SUBTOTAL", () => {
3133+
const grid = {
3134+
A1: "1",
3135+
A2: "1",
3136+
A3: "=SUBTOTAL(9, A1:A2) + A1:A2",
3137+
A5: "=SUBTOTAL(9, A4)",
3138+
};
3139+
const gridResult = evaluateGrid(grid);
3140+
expect(gridResult.A3).toBe(3);
3141+
expect(gridResult.A5).toBe(0);
3142+
});
3143+
31323144
describe("ignoring filtered rows", () => {
31333145
test("write the SUBTOTAL formula after updating filter", () => {
31343146
const model = new Model();

0 commit comments

Comments
 (0)