/pigment:writing-performant-formulasfrom Pigment
Reviews Pigment formulas for performance before delivery. Covers sparsity preservation, scope-first patterns, and a mandatory pre-delivery checklist.
Ships in Pigment. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Apply this skill to every formula before delivery. Pigment is a sparse multidimensional engine: only defined cells are stored. Performance depends on keeping formulas sparse and scoped.
Simple same-dimension arithmetic (e.g. 'A' + 'B') needs no special performance wrapping. Always review the checklist; deep rewrite when any item fails. For profiler-based troubleshooting after delivery, see skill:diagnosing-performance-issues.
Before delivering any formula, verify each item. Rewrite until all pass.
'Revenue'), double quotes for items and text literals.ADD or dimension mismatch.0, FALSE, or TRUE where BLANK suffices.ISDEFINED / IFDEFINED / IFBLANK over ISBLANK / ISNOTBLANK (see skill:using-formula-functions for rare valid exceptions).FILTER, EXCLUDE, or IFDEFINED appear before calculations, not after.REMOVE, BY, and other aggregations come after the core calculation.SELECT with offset — not PREVIOUS unless true iteration is required (see skill:iterating-with-previous-and-cycles).BY with a mapping when one exists — not ADD.PRORATA — not IF(Date >= Start AND Date <= End, ...).IF / ISBLANK wrappers on BY when the source is dimension-typed.EXCLUDE: condition over FILTER: NOT(condition).IFDEFINED('Users roles', ...). Optionally add IFDEFINED(User, ...) as an additional performance trim.IF(condition, value) (sparse) — not IF(condition, value, 0) or IF(condition, TRUE, FALSE).FILTER: CurrentValue — not IF(expr, expr, BLANK).| State | Stored? | Meaning |
|---|---|---|
BLANK / undefined | No | Cell does not exist |
0 | Yes | Explicit numeric zero |
FALSE / TRUE | Yes | Explicit boolean |
Example: 1000 Products x 12 Months = 12,000 possible cells. If only 500 have values, sparse metric stores 500 cells (~4%). Densifying to 12,000 multiplies storage and computation.
Rule: Represent "no value" with BLANK. Never substitute 0 for empty numbers or FALSE for empty booleans unless downstream logic explicitly requires stored values.
Meaningful zero exception: Explicit 0 IS correct when zero is a business value (zero variance, zero balance, zero growth rate, inactive line item contributing 0 to a total). In these cases BLANK would incorrectly omit the line from aggregations.
ISBLANK(A) returns TRUE or FALSE for every cell (dense). ISDEFINED(A) returns TRUE only where a value exists, BLANK elsewhere (sparse). Reserve ISBLANK / ISNOTBLANK only when every cell must hold an explicit boolean — see skill:using-formula-functions for the rare-valid-exception allow-list.
// WRONG — densifies
IF(ISBLANK('Revenue'), 'Default', 'Revenue')
// CORRECT — sparse
IFBLANK('Revenue', 'Default')
IFDEFINED('Revenue', 'Revenue')
Put narrowing modifiers and guards before calculations; aggregations after.
// WRONG — computes on all cells, then filters
('Revenue' * 'Rate')[FILTER: 'Region' = SET_Selected_Region]
// CORRECT — scope first, then calculate, then aggregate
'Revenue'
[FILTER: 'Region' = SET_Selected_Region]
* 'Rate'
[REMOVE: Product]
Pattern: Source [scope modifiers] → calculation → [REMOVE / BY aggregation].
PRORATA(TimeDimension, StartDate, EndDate) returns the fraction of each period within [StartDate, EndDate). Start date is included; end date is excluded; add 1 for inclusive end.
// WRONG — verbose, error-prone, poor sparsity
IF('Date' >= 'Start Date' AND 'Date' <= 'End Date', 1, BLANK)
// CORRECT — sparse presence factor
PRORATA(Month, 'Start Date', 'End Date' + 1)
Derive presence booleans with ISDEFINED(PRORATA(...)), not ISBLANK(PRORATA(...)).
Use SELECT with offset for simple lags — not PREVIOUS (iterative, expensive).
PREVIOUS(Month) is correct only for true iterative calculations within a single metric (e.g. cumulative balance, cash roll-forward, inventory carry-forward). For multi-metric iteration (opening/closing inventory across metrics), use PREVIOUSOF(...) with a cycle. See skill:iterating-with-previous-and-cycles for patterns.
BY follows a mapping (sparse); ADD creates all combinations (dense).
BY CONSTANT with a mapping for value replication instead of ADD CONSTANT (dense).BY with IF(ISBLANK(...)) guards on dimension-typed metrics.ADD+FILTER and round-trip patterns.IFDEFINED('Users roles', ...) wrapping is mandatory for access rights formulas. IFDEFINED(User, ...) is an optional additional trim — not a substitute for IFDEFINED('Users roles', ...).
// Mandatory wrapping
IFDEFINED('Users roles', 'Can Edit'[BY: User])
// Optional additional trim layered on top
IFDEFINED(User, IFDEFINED('Users roles', 'Can Edit'[BY: User]))
Use BLANK (not FALSE) for denied access to preserve sparsity.
Use IF(condition, value) to create values sparsely — [ADD: X][FILTER: condition] densifies first, then subsets.
FILTER only on already-computed values; prefer [FILTER: CurrentValue] over IF(expr, expr, BLANK).EXCLUDE instead of FILTER: NOT(...).SELECT (aggregates it away) rather than FILTER (keeps dimension in output).BLANK); do not guard with IF(x <> 0, a / x).Scan every formula for these patterns. Each row is a rewrite trigger.
| Anti-Pattern | Why Bad | Fix |
|---|---|---|
ISBLANK/ISNOTBLANK for existence checks | Densifies (TRUE/FALSE stored everywhere) | ISDEFINED/IFDEFINED/IFBLANK; e.g. IFBLANK(A, B) not IF(ISBLANK(A), B, A) |
ISBLANK/ISNOTBLANK in AND/OR chains | Densifies entire expression via blank-presence | EXCLUDE to remove blank rows, or nested IFDEFINED guards |
0/FALSE for empty numeric/boolean | Stores explicit value, destroys sparsity | BLANK (absence = not stored) |
| Calculations before scoping | Computes irrelevant cells | FILTER / EXCLUDE / IFDEFINED first |
PREVIOUS for simple lag; SELECT for iterative calc | Lag: iterative overhead; Iterative: circular ref | Lag: [SELECT: Month - 1]; same-metric: PREVIOUS(Month); multi-metric: PREVIOUSOF(...) + cycle — skill:iterating-with-previous-and-cycles |
ADD/ADD CONSTANT/ADD+FILTER when mapping or IF fits | Dense cross-product or dense replication | BY with mapping; BY CONSTANT for replication; IF(condition, value) for conditional rows |
IF/ISBLANK guard on BY with dim-typed metric | Redundant, densifies | Remove guard |
IF(Date >= Start AND Date <= End, 1, BLANK) | Verbose, error-prone | PRORATA(TimeDim, Start, End + 1) |
ISBLANK(PRORATA(...)) for presence | Densifies | ISDEFINED(PRORATA(...)) |
FILTER: NOT(condition) | Less sparse-friendly | EXCLUDE: condition |
IF(cond, val, 0) or IF(cond, TRUE, FALSE) | Densifies | IF(cond, val) or IFBLANK |
IF(expr, expr, BLANK) for subsetting | Redundant branching | [FILTER: CurrentValue] |
FILTER to aggregate away a dimension | Keeps dimension in output | SELECT to aggregate; FILTER to keep dimension |
IF(x<>0, a/x) for safe division | Unnecessary guard | Just divide — Pigment returns BLANK for division by zero |
Access rights without IFDEFINED('Users roles', ...) | Densifies across users | IFDEFINED('Users roles', ...) mandatory; IFDEFINED(User, ...) is a trim, not a substitute |
[ADD: X][REMOVE: X] or [REMOVE: X][ADD: Y] round-trips | Unnecessary expand/collapse | BY with a mapping |
Chained [BY:][BY:] on Transaction Lists | Silently drops list properties between steps | Single BY with comma-separated mappings |
[REMOVE: Version] without verification | Collapses scenario meaning | Verify collapse is intentional |
CUMULATE/MOVINGSUM/FIND/SUBSTITUTE on large lists | Expensive per-cell | Subset with FILTER first |
Multiple PREVIOUS(...) in one formula | Multiplies iterative passes | Single PREVIOUS call |
IFBLANK(X, PREVIOUS(Dim)) or IFBLANK(X, PREVIOUSOF(...)) | Verbose, triggers iteration | FILLFORWARD |
ACCESSRIGHTS(x, FALSE) for denied access | Densifies with explicit FALSE | ACCESSRIGHTS(x, BLANK) |
2-arg IF(condition, expr) on 6+ dim metric | Expands scope across all intersections | expr[FILTER: condition] |
Hard-coded year literals or DATE(YYYY, ...) | Breaks across fiscal years | Date-typed or Dimension-typed input metrics |
Remember: BLANK = undefined = not stored. FALSE ≠ BLANK (stored, densifies). 0 ≠ BLANK (stored). Always prefer absence over explicit empty values unless business logic demands a stored zero or boolean.
skill:diagnosing-performance-issues — profiler-based troubleshooting of delivered formulasskill:iterating-with-previous-and-cycles — iterative calculation optimizationskill:using-formula-functions — ISBLANK rare-valid-exception allow-listWhat SKILL.md sets; muted values are Claude Code's defaults
39 skills in this plugin
/aggregating-view-dataExecution skill. Use when a View needs totals or subtotals, when a value must roll up with something other than Sum (average, min, max, count, last), when a snapshot metric adds up across time instead of holding, or when a ratio, percentage, margin, growth or variance metric is added to a Table View or shows a wrong total (e.g. a row for margin as a percent of revenue). Covers metric default aggregators, pivot versus hidden-dimension aggregation, the aggregator reference per value type, and Advanced Aggregators on Table Views./architecting-multi-application-solutionsPlanning skill. Use when deciding how to split work across Pigment applications, designing Hub-and-spoke data flows, or planning Test & Deploy across environments./auditing-a-pigment-applicationExecution skill. Use when auditing, reviewing, or health-checking a Pigment application. Covers the structured audit checklist, severity classification, and output format. Also triggers on requests to clean up, find unused blocks, assess model quality, or find what is wrong with an application./building-a-full-applicationPlanning skill. Use when building a complete Pigment application from scratch or when the request spans multiple modeling phases. This skill, together with any other planning skill the request calls for, is sufficient to produce the full architecture spec; do not load execution skills until the spec is approved and you begin building blocks./building-pigment-framesUse this skill whenever you're building, updating, or troubleshooting a Pigment Frame — a full-page, custom-coded visualisation (JavaScript, canvas, or inline SVG) that reads Pigment data through the PigmentSDK. Reach for it any time a native View (Grid, Chart, KPI) or Board can't produce what's being asked for - a bespoke chart, a custom canvas drawing, an interactive widget, or a standalone page in the left navigation that behaves like a small app. Also use it if a Frame you've already built shows up blank or broken and needs debugging./building-versions-and-planning-cyclesExecution skill. Use when implementing versions, planning cycles, or actuals vs forecast separation, and whenever realized data is extended into a plan or budget — loading actuals then planning the remaining periods, forecasting forward from actuals, Actual/Budget/Plan layering, plan vs actual variance — even when the request never uses the word version. Covers Version Dimensions, Switchover patterns, Actual/Forecast layering, Native Scenarios, and Snapshots.Other plugins' skills for the same job
npx claudepluginhub gopigment/ai-plugins --plugin pigment