/pigment:writing-pigment-formulasfrom Pigment
Guides writing, editing, and debugging Pigment metric and list property formulas with quoting rules, data types, modifiers, and input identification.
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.
Pigment syntax only. Never write Excel, SQL, Python, DAX, or any other language.
Formulas operate on metrics (multidimensional grids). Each cell = intersection of one item per dimension. Modifiers control dimension alignment.
Before writing any formula:
tool:search_metrics_and_lists (or tool:semantic_search when names are unclear) to find exact names and spot duplicates.Every medium-to-complex formula should be explained with a comment: above the formula, restate its logic in Structured English, in evaluation order, using business terms and friendly names. A reader who doesn't know Pigment must be able to understand it.
Guidance on commenting:
// only; no block comments.// IF the period is an actual period
// then aggregate the actuals from the data
// else bring the planning numbers from the other applications
| Reference type | Quotes | Example |
|---|---|---|
| Metric / dimension / property / list name | Single '...' | 'Revenue', 'Product'.'Category' |
| Dimension item | Double "..." after dim | Type."Revenue", Status."Active" |
| Text literal | Double "..." | "Active", "Completed" |
| Cross-app block (via Library) | 'App'::'Block' | 'Finance'::'Revenue' |
| List property | 'List'.'Property' | 'Employee'.'Start Date' |
Full item path: 'List'.'Property'."Item" — default property can be omitted: Status."Active".
⛔ Never hard-code dimension items, dates or thresholds in formulas.
Month."Jun 24", Version."Actual", Country."France", DATE(2024, 1, 1), 'Revenue' > 50000 are all forbidden.
[SELECT LASTNONBLANK: 'Is Actual'] or equivalent flag metric.Version."Actual" in a Version-aware
application where that item is guaranteed to always exist and never be renamed).Always quote identifiers even when Pigment allows omitting quotes on simple names.
Build the expression without modifiers first. Pass only the function arguments the requirement calls for — do not add extra optional parameters speculatively. Use the correct operators for the data type:
| Type | Operators | Notes |
|---|---|---|
| Number | + - * / = <> < > <= >= | BLANK propagates on *, /, AND; division by zero → BLANK |
| Date | = <> < > <= >= + - | +/- for day offsets; use date functions for month/year logic |
| Text | = <> & | & concatenation; wrap numbers with TEXT() |
| Dimension | = | From dim-typed properties or mapping metrics |
| Boolean | AND OR NOT = <> | 3-state: TRUE / FALSE / BLANK |
A bare comparison (e.g. Day = Department.'Start Date') is dense: FALSE everywhere it doesn't hold, not BLANK. When comparing against a sparse property, wrap it — IF(Day = Department.'Start Date', TRUE, BLANK) — to keep the result sparse.
Syntax: Block[MODIFIER Method: arguments]
| Need | Modifier | Effect |
|---|---|---|
| Aggregate child → parent | [BY SUM: Dim.Parent] | Replaces dim |
| Allocate parent → child, same value | [BY CONSTANT: Dim.Parent] | Replicates value to each child |
| Allocate parent → child, divided | [BY SPLIT: Dim.Parent] | Divides value equally across children |
| Drop a dimension | [REMOVE SUM: Dim] | Removes dim |
| Filter, keep dimension | [FILTER: condition] | Sparse subset |
| Exclude rows | [EXCLUDE: condition] | Opposite of FILTER; preserves sparsity |
Allocation method defaults to CONSTANT — if the request says "split," "distribute," "divide equally," or "spread," use SPLIT explicitly instead.
Prefer BY over ADD when a mapping exists — BY is sparse (only allocates where the mapping is defined); ADD is dense (full cross-product) and should be reserved for cases with no mapping.
CurrentValue = value of the expression the modifier applies to: 'Revenue'[FILTER: CurrentValue > 1000]
Transaction lists: always use a single BY with all dimension mappings. Never chain BY (properties are lost after first aggregation).
// ✅ Single BY with all mappings — use stored Month property (not inline TIMEDIM)
'Orders'.'Amount'[BY SUM: 'Orders'.'Month', 'Orders'.'Product']
// Month property on the TL has formula: TIMEDIM('Orders'.'Date', Month)
Full modifier reference: skill:using-formula-modifiers
Full reference with syntax → skill:using-formula-functions. Key categories:
| Category | Functions | Use when |
|---|---|---|
| Conditional | IF, SWITCH, IFBLANK, IFDEFINED | Branching; override chains; sparsity guards |
| Aggregation | SUMOF, AVGOF, COUNTOF, MINOF, MAXOF | Aggregate a list property without BY |
| Text | LEFT, RIGHT, MID, FIND, SUBSTITUTE, TEXT, VALUE, &, CONTAINS | String manipulation; type conversion; CONTAINS(substring, haystack) — substring first |
| Date / Time | DATE, YEAR, MONTH, DAY, NETWORKDAYS, DAYSINPERIOD, PRORATA | Date arithmetic; period coverage |
| Numeric | ROUND, ROUNDUP, ROUNDDOWN, ABS, MIN, MAX, RANK, MOVINGSUM, CUMULATE | Rounding; ranking; rolling windows |
| Lookup | MATCH, ITEM | Find items in lists; convert text to dimension |
| Iterative | PREVIOUS, PREVIOUSOF | Time-series accumulation (PREVIOUSOF requires cycles); see below |
| Utility | TIMEDIM, ISDEFINED, IN, SHIFT | Date→dim conversion; existence check; set membership; dimension offset |
| Finance | NPV, IRR, XNPV, XIRR | Discounted cash flow; internal rate of return |
| Forecasting | FORECAST_ETS, FORECAST_LINEAR | Statistical forecasting |
Never invent functions. Only use documented Pigment functions from the reference above.
Iterative patterns:
IFDEFINED(PREVIOUS(Month), PREVIOUS(Month) * (1 + 'Growth Rate'), 'Seed Value')FILLFORWARD('FX Rate Input', Month)skill:iterating-with-previous-and-cyclesBLANK = not stored (sparse). 0 / FALSE = stored (dense).
| Expression | Result | Why |
|---|---|---|
BLANK + 5 | 5 | Additive identity |
BLANK * 5 | BLANK | Multiplicative propagation |
X / 0 or X / BLANK | BLANK | Auto-handled; no guard needed |
NOT(BLANK) | BLANK | NOT does not flip BLANK to TRUE |
Rules:
BLANK where no value should exist; never substitute 0 or FALSESparsity preference rules (IFDEFINED vs ISBLANK), performance anti-patterns: skill:writing-performant-formulas
You MUST call tool:validate_formula before passing a formula to tool:create_metric, tool:bulk_update_metrics, tool:create_list_property, or tool:update_list_property. The only exception is PREVIOUS/PREVIOUSOF formulas without a target metric — those cannot be validated standalone; pass target.metric_id for an existing metric to validate them normally. Applying an unvalidated formula puts the metric or property into an error state.
Run through this checklist first:
If the task requires both a structural change (adding/removing dimensions, changing type) and a formula
update on the same metric or list property, apply the structural change first, then call
tool:validate_formula. The validator checks against the block's current live structure — validating before
applying the structural change tests the formula against the old structure and produces misleading results.
Adding or removing a structural dimension on a metric does not automatically propagate to the metrics that reference it. If a downstream formula does not already carry the new dimension, the compiler silently broadcasts or collapses values to align with the target instead of failing — wrong numbers, no visible error.
Do NOT assume a referencing formula "just passes the dimension through". Before declaring a structural dimension change done:
tool:validate_formula with that metric's formula and target.metric_id set to it — the target is what surfaces the mismatch.This applies once per changed metric in the chain, not once for the whole change: validate each metric after its own dimension and formula update, before moving on to the next one.
skill:using-formula-modifiers — modifier mechanics, arrow-mapping syntax, aggregation methodsskill:using-formula-functions — all function signatures and examplesskill:writing-performant-formulas — sparsity rules, anti-patterns, pre-delivery checklistskill:choosing-formula-patterns — business requirement → pattern mappingskill:iterating-with-previous-and-cycles — PREVIOUS/PREVIOUSOF cyclesWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
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./npx claudepluginhub gopigment/ai-plugins --plugin pigmentOther plugins' skills for the same job