iOfficeAI/OfficeCLI · error · ArgumentException

invalid showDataAs: '{showAs}'. Valid: normal, percent_of_to

Error message

invalid showDataAs: '{showAs}'. Valid: normal, percent_of_total, percent_of_row, percent_of_col, running_total

What it means

The showAs token did not match any recognised spelling (snake_case or camelCase aliases) and was not one of the explicitly-unsupported-but-known tokens either. The default switch arm rejects it so users see typos at Add/Set time rather than getting a silent fallback to 'normal'. The message enumerates the valid tokens.

Source

Thrown at src/officecli/Core/PivotTableHelper.Parse.cs:464

            "" or "normal" => null,
            "percent_of_total" or "percentoftotal" or "percent" => ShowDataAsValues.PercentOfTotal,
            "percent_of_row" or "percentofrow" => ShowDataAsValues.PercentOfRaw,
            "percent_of_col" or "percent_of_column" or "percentofcol" or "percentofcolumn" => ShowDataAsValues.PercentOfColumn,
            "running_total" or "runningtotal" or "runtotal" => ShowDataAsValues.RunTotal,
            // CONSISTENCY(strict-enums): difference / percent_diff / index are
            // accepted by the OOXML ShowDataAsValues enum, but ApplyShowDataAs1x1
            // has no matrix transformation for them, so rendered cells would
            // silently equal the raw aggregate. Reject up front until a proper
            // renderer exists, mirroring the invalid-sort / invalid-aggregate
            // policy from Round 1.
            "difference" or "diff" or "percent_diff" or "percentdiff" or "index" =>
                throw new ArgumentException(
                    $"showDataAs '{showAs}' is not yet supported by the renderer " +
                    "(would silently return raw aggregate). Supported: normal, " +
                    "percent_of_total, percent_of_row, percent_of_col, running_total."),
            // CONSISTENCY(strict-enums): unknown showAs tokens are rejected
            // up front so users see typos at Add/Set time, not on render.
            _ => throw new ArgumentException(
                $"invalid showDataAs: '{showAs}'. Valid: normal, percent_of_total, percent_of_row, " +
                "percent_of_col, running_total"),
        };
    }

    // R11-2: Right-to-left value-spec parser support. Token recognizers
    // mirror the cases ParseSubtotal / ParseShowDataAs accept (lowercase
    // canonical only — we lowercase the token before calling). Keep these
    // in sync if new aggregates / showAs tokens are added downstream.
    private static bool IsKnownAggregateToken(string token) => token switch
    {
        "sum" or "count" or "countnums" or "countnum" or "average" or "avg" or
        "max" or "min" or "product" or "stddev" or "std" or "stddevp" or "stdp" or
        "var" or "variance" or "varp" => true,
        _ => false,
    };

    private static bool IsKnownShowAsToken(string token) => token switch

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Use one of the exact valid tokens: normal, percent_of_total, percent_of_row, percent_of_col, running_total
  2. Drop the showAs segment entirely if you want the default 'normal'
  3. Double-check spelling and separators against the message's valid list

Example fix

// before
values="Sales:sum:pecent_of_total"
// after
values="Sales:sum:percent_of_total"
Defensive patterns

Strategy: validation

Validate before calling

var valid = new[] { "normal", "percent_of_total", "percent_of_row", "percent_of_col", "running_total" };
if (!valid.Contains(showAs.ToLowerInvariant()))
    throw new InvalidOperationException($"Invalid showDataAs '{showAs}'");

Type guard

static readonly HashSet<string> ValidShowAs = new(StringComparer.OrdinalIgnoreCase)
{ "", "normal", "percent_of_total", "percentoftotal", "percent",
  "percent_of_row", "percentofrow",
  "percent_of_col", "percent_of_column", "percentofcol", "percentofcolumn",
  "running_total", "runningtotal", "runtotal" };
static bool IsValidShowAs(string s) => ValidShowAs.Contains(s);

Try / catch

try { BuildPivot(props); }
catch (ArgumentException ex) when (ex.Message.Contains("invalid showDataAs"))
{ /* correct the spelling against the valid list in the message */ }

Prevention

When it happens

Trigger: values=Sales:sum:pecent_of_total (typo 'pecent'); values=Sales:sum:Percentage (not a recognised alias); values=Sales:sum:run_total (wrong separator — should be running_total).

Common situations: Typos; users guessing at token names from Excel UI labels rather than the CLI vocabulary; case or separator mistakes (the parser lowercases first, but the literal spelling must still match).

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/7719726b72ddb60f. Report an issue: GitHub.