{"record":{"id":"ab1751a7e3ee004b","repo":"iOfficeAI/OfficeCLI","slug":"labelfilter-field-fieldname-not-found-in-sourc","errorCode":null,"errorMessage":"labelFilter field '{fieldName}' not found in source headers","messagePattern":"labelFilter field '(.+?)' not found in source headers","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/PivotTableHelper.cs","lineNumber":845,"sourceCode":"        { FieldIdx = fieldIdx; OpType = opType; Needle = needle; Match = match; }\n    }\n\n    private static LabelFilterSpec? ParseLabelFilterSpec(\n        string[] headers, Dictionary<string, string> properties)\n    {\n        if (!properties.TryGetValue(\"labelFilter\", out var spec) || string.IsNullOrEmpty(spec))\n            return null;\n        var parts = spec.Split(':', 3);\n        if (parts.Length != 3)\n            throw new ArgumentException(\n                $\"labelFilter must be 'field:type:value', got: '{spec}'\");\n        var fieldName = parts[0].Trim();\n        var opType = parts[1].Trim().ToLowerInvariant();\n        var needle = parts[2];\n\n        int fieldIdx = Array.FindIndex(headers, h => string.Equals(h, fieldName, StringComparison.Ordinal));\n        if (fieldIdx < 0)\n            throw new ArgumentException($\"labelFilter field '{fieldName}' not found in source headers\");\n\n        Func<string, bool> match = opType switch\n        {\n            \"contains\" => v => v != null && v.IndexOf(needle, StringComparison.Ordinal) >= 0,\n            \"doesnotcontain\" => v => v == null || v.IndexOf(needle, StringComparison.Ordinal) < 0,\n            \"beginswith\" => v => v != null && v.StartsWith(needle, StringComparison.Ordinal),\n            \"endswith\" => v => v != null && v.EndsWith(needle, StringComparison.Ordinal),\n            \"equals\" => v => string.Equals(v, needle, StringComparison.Ordinal),\n            \"notequals\" => v => !string.Equals(v, needle, StringComparison.Ordinal),\n            _ => throw new ArgumentException(\n                $\"labelFilter type must be one of contains/doesNotContain/beginsWith/endsWith/equals/notEquals, got: '{opType}'\"),\n        };\n        return new LabelFilterSpec(fieldIdx, opType, needle, match);\n    }\n\n    /// <summary>\n    /// Apply a parsed labelFilter spec to columnData in place (drop\n    /// non-matching rows). Used by the render path's data shaping when","sourceCodeStart":827,"sourceCodeEnd":863,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/PivotTableHelper.cs#L827-L863","documentation":"Thrown by ParseLabelFilterSpec when the field name (first segment of the labelFilter spec) does not match any header in the source data's headers array. The lookup uses Array.FindIndex with ordinal case-sensitive comparison, so the field name must match a source header exactly (same spelling and case).","triggerScenarios":"Calling labelFilter='Regon:contains:North' (typo in field name); labelFilter='region:contains:North' (wrong case — headers are case-sensitive); labelFilter='Sales Amount:contains:High' when the header is 'Amount'. The field must exist in the current source headers.","commonSituations":"Case mismatch (the comparison is Ordinal/case-sensitive); typo in the field name; referencing a field that was renamed or is in a different source range; after source narrowing (error 345 path) the field no longer exists.","solutions":["Verify the exact field name and case against the source headers (Get the source headers first).","Match the case exactly — 'Region' not 'region' if the header is capitalized.","If the field was renamed, use the current header name.","Confirm the field exists in the source range the pivot reads from."],"exampleFix":"// before — header is 'Region' (capital R)\nSet pivot labelFilter='region:contains:North'\n// after\nSet pivot labelFilter='Region:contains:North'","handlingStrategy":"validation","validationCode":"// Case-sensitive check before applying the filter\nint fieldIdx = Array.FindIndex(headers, h => string.Equals(h, fieldName, StringComparison.Ordinal));\nif (fieldIdx < 0)\n    throw new ArgumentException($\"labelFilter field '{fieldName}' not found. Available: {string.Join(\", \", headers)}\");","typeGuard":"static bool FieldExistsInHeaders(string[] headers, string fieldName) =>\n    Array.Exists(headers, h => string.Equals(h, fieldName, StringComparison.Ordinal));","tryCatchPattern":null,"preventionTips":["Match the field name's case exactly — the lookup is Ordinal/case-sensitive.","Get the source headers first to confirm the exact spelling.","After narrowing a source, verify all labelFilter fields still exist."],"tags":["pivot","excel","label-filter","field-not-found","case-sensitive","validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}