{"record":{"id":"45cda08544909c9d","repo":"iOfficeAI/OfficeCLI","slug":"invalid-aggregate-func-valid-sum-count-co","errorCode":null,"errorMessage":"invalid aggregate: '{func}'. Valid: sum, count, countNums, average/avg, max, min, product, stdDev/std, stdDevp/stdp, var/variance, varP","messagePattern":"invalid aggregate: '(.+?)'\\. Valid: sum, count, countNums, average/avg, max, min, product, stdDev/std, stdDevp/stdp, var/variance, varP","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/PivotTableHelper.Parse.cs","lineNumber":551,"sourceCode":"    {\n        return func.ToLowerInvariant() switch\n        {\n            \"sum\" => DataConsolidateFunctionValues.Sum,\n            \"count\" => DataConsolidateFunctionValues.Count,\n            \"countnums\" or \"countnum\" => DataConsolidateFunctionValues.CountNumbers,\n            \"average\" or \"avg\" => DataConsolidateFunctionValues.Average,\n            \"max\" => DataConsolidateFunctionValues.Maximum,\n            \"min\" => DataConsolidateFunctionValues.Minimum,\n            \"product\" => DataConsolidateFunctionValues.Product,\n            \"stddev\" or \"stdev\" or \"std\" => DataConsolidateFunctionValues.StandardDeviation,\n            \"stddevp\" or \"stdevp\" or \"stdp\" => DataConsolidateFunctionValues.StandardDeviationP,\n            \"var\" or \"variance\" => DataConsolidateFunctionValues.Variance,\n            \"varp\" => DataConsolidateFunctionValues.VarianceP,\n            // CONSISTENCY(strict-enums): mirror ParseShowDataAs / ParseFieldList —\n            // unknown tokens throw at Add/Set time so typos surface immediately\n            // instead of silently falling back to sum and producing the wrong\n            // numbers on render (Bug #3).\n            _ => throw new ArgumentException(\n                $\"invalid aggregate: '{func}'. Valid: sum, count, countNums, average/avg, \" +\n                \"max, min, product, stdDev/std, stdDevp/stdp, var/variance, varP\"),\n        };\n    }\n\n    /// <summary>\n    /// Aggregate a bag of numeric values using the given subtotal function.\n    /// Matches the ScDPAggData semantics:\n    ///   sum / product / min / max / count : trivial\n    ///   countNums : count of numeric entries (identical to count here because\n    ///     the caller only places parsed numerics into the bag)\n    ///   average : arithmetic mean\n    ///   stdDev  : sample std-dev  (sqrt(Σ(x-μ)²/(n-1))), requires n≥2\n    ///   stdDevp : population std-dev (sqrt(Σ(x-μ)²/n)), requires n≥1\n    ///   var     : sample variance (Σ(x-μ)²/(n-1)), requires n≥2\n    ///   varp    : population variance (Σ(x-μ)²/n), requires n≥1\n    /// Returns 0 for empty input and for stdDev/var when n&lt;2, matching the\n    /// existing 0-on-empty convention that the rest of the renderer assumes.","sourceCodeStart":533,"sourceCodeEnd":569,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/PivotTableHelper.Parse.cs#L533-L569","documentation":"ParseSubtotal rejects any aggregate token that does not match a recognised function name or alias. The strict check exists because an earlier version silently fell back to 'sum' on unknown tokens, producing wrong numbers on render (Bug #3). The message lists the valid spellings including aliases so the user can correct the typo in place.","triggerScenarios":"values=Sales:tottal (typo); values=Sales:mean (not an alias — use 'average' or 'avg'); values=Sales:stdeviation (too long — use 'stddev' or 'std'); aggregate=tottal,sum override list with a typo.","commonSituations":"Typos; users entering Excel UI function labels that do not match the CLI vocabulary; mismatches between the aggregate= override list and the values= list length exposing an unintended token.","solutions":["Use a valid token from the message: sum, count, countNums, average/avg, max, min, product, stdDev/std, stdDevp/stdp, var/variance, varP","Omit the function segment to use the default 'sum': values=Sales","Check the aggregate= override list for typos if you use that sibling property"],"exampleFix":"// before\nvalues=\"Sales:tottal\"\n// after\nvalues=\"Sales:sum\"","handlingStrategy":"validation","validationCode":"var validAgg = new[] { \"sum\", \"count\", \"countnums\", \"countnum\", \"average\", \"avg\",\n    \"max\", \"min\", \"product\", \"stddev\", \"stdev\", \"std\", \"stddevp\", \"stdevp\", \"stdp\",\n    \"var\", \"variance\", \"varp\" };\nif (!validAgg.Contains(func.ToLowerInvariant()))\n    throw new InvalidOperationException($\"Invalid aggregate '{func}'\");","typeGuard":"static readonly HashSet<string> ValidAgg = new(StringComparer.OrdinalIgnoreCase)\n{ \"sum\", \"count\", \"countnums\", \"countnum\", \"average\", \"avg\", \"max\", \"min\", \"product\",\n  \"stddev\", \"stdev\", \"std\", \"stddevp\", \"stdevp\", \"stdp\", \"var\", \"variance\", \"varp\" };\nstatic bool IsValidAggregate(string s) => ValidAgg.Contains(s);","tryCatchPattern":"try { BuildPivot(props); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"invalid aggregate\"))\n{ /* correct the token against the valid list */ }","preventionTips":["Use exact spellings from the valid-aggregate list","Omit the function segment to default to 'sum'","Check the aggregate= override list for typos"],"tags":["pivottable","aggregate","strict-enum","typo","argument-validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}