{"record":{"id":"9e2df3a08aac8f78","repo":"iOfficeAI/OfficeCLI","slug":"pivot-output-range-overlaps-existing-pivot-exist","errorCode":null,"errorMessage":"Pivot output range overlaps existing pivot '{existingPivot.Name?.Value}' at {existingLoc}; choose a different anchor (--prop position=...).","messagePattern":"Pivot output range overlaps existing pivot '(.+?)' at (.+?); choose a different anchor \\(--prop position=\\.\\.\\.\\)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs","lineNumber":1773,"sourceCode":"                        $\"pivot at {ptPosition} does not fit: computed end col={minEndColIdx} row={minEndRow} exceeds sheet dimensions (max XFD1048576)\");\n                }\n\n                // CONSISTENCY(pivot-output-overlap): two pivot tables whose\n                // <x:location> rectangles overlap on the same sheet make\n                // Excel surface a \"found a problem\" repair dialog because\n                // the output cells fight for ownership. Mirror the T4\n                // table-table overlap check using the conservative output\n                // bounds computed above. Cross-sheet pivots are fine.\n                var newPivotRange = $\"{IndexToColumnName(anchorColIdx)}{anchorRow}:\" +\n                                    $\"{IndexToColumnName(minEndColIdx)}{minEndRow}\";\n                foreach (var existingPivot in ptWorksheet.PivotTableParts\n                    .Select(ptp => ptp.PivotTableDefinition)\n                    .Where(d => d != null))\n                {\n                    var existingLoc = existingPivot!.Location?.Reference?.Value;\n                    if (string.IsNullOrEmpty(existingLoc)) continue;\n                    if (RangesOverlap(newPivotRange.ToUpperInvariant(), existingLoc.ToUpperInvariant()))\n                        throw new ArgumentException(\n                            $\"Pivot output range overlaps existing pivot \" +\n                            $\"'{existingPivot.Name?.Value}' at {existingLoc}; \" +\n                            $\"choose a different anchor (--prop position=...).\");\n                }\n            }\n        }\n\n        // CONSISTENCY(tracking-rebind): CreatePivotTable internally rebinds\n        // `properties` to a fresh non-tracking dictionary via\n        // NormalizePivotProperties, so all subsequent TryGetValue calls\n        // would never reach our TrackingPropertyDictionary comparer. Mark\n        // every input key whose normalized form is a known pivot property\n        // as consumed up-front, so they don't surface as false\n        // unsupported_property warnings. Keys the helper genuinely doesn't\n        // know about are still flagged via WarnUnknownPivotProperties +\n        // CollectUnknownPivotKeys (R12-1).\n        if (properties is OfficeCli.Core.TrackingPropertyDictionary ptTracking)\n        {","sourceCodeStart":1755,"sourceCodeEnd":1791,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs#L1755-L1791","documentation":"Thrown by AddPivotTable's output-overlap guard when the conservative output rectangle of the new pivot intersects the <location> reference of an existing pivot on the same host sheet. Two overlapping pivots make Excel surface a 'found a problem' repair dialog because the output cells fight for ownership; this mirrors the table-table overlap check. Cross-sheet pivots are not compared.","triggerScenarios":"Adding a second pivot whose anchor (position) produces an output range overlapping an existing pivot's location on the same sheet, even partially.","commonSituations":"Re-adding a pivot without removing the old one, auto-positioning landing on an existing pivot, or stacking pivots at the same anchor.","solutions":["Choose a different anchor with --prop position=... that does not overlap the existing pivot.","Remove or relocate the existing pivot first.","Put the new pivot on a different sheet (cross-sheet overlap is allowed)."],"exampleFix":"// before (existing pivot at A1:F20)\nadd /Report/pivottable --prop source=Data!A1:D100 --prop position=C5\n// after\nadd /Report/pivottable --prop source=Data!A1:D100 --prop position=H1","handlingStrategy":"validation","validationCode":"// Check the candidate pivot output range against existing pivots on the host sheet before Add.\nstatic bool OverlapsExistingPivot(ExcelHandler h, string sheet, string newRange)\n{\n    foreach (var loc in h.ListPivotLocations(sheet)) // pseudo\n        if (RangesOverlap(newRange.ToUpperInvariant(), loc.ToUpperInvariant()))\n            return true;\n    return false;\n}","typeGuard":null,"tryCatchPattern":"try { handler.Add(parentPath, \"pivottable\", null, props); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"overlaps existing pivot\"))\n{ /* choose a different position or remove the existing pivot, then retry */ }","preventionTips":["Track pivot output ranges per sheet to choose non-overlapping anchors.","Remove or relocate existing pivots before re-adding in idempotent scripts.","Remember overlap is per-sheet; cross-sheet pivots do not conflict."],"tags":["excel","pivot-table","validation","range-overlap","corruption-prevention"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}