Calculated Fields Grow Up: Table Calculations, LOD Aggregates, and Date Math in CanvasXpress
If you've ever built a Pareto chart, a "percent of category" bar, or a month-over-month trend line in Tableau or Power BI, you know the drill: you reach for a table calculation or a {FIXED} expression, and the tool quietly does the heavy lifting of ordering rows, partitioning by a dimension, and rejoining an aggregate back to every record. CanvasXpress's calculated-field engine now does the same thing — natively, inside the chart, with no spreadsheet pre-processing and no server round-trip.
Calculated fields in CanvasXpress have always let you derive a new variable or annotation from a formula — things like log2(Expression) or (Price - Cost) / Price. What's new is a set of grouped aggregates, ordered window functions, and a date arithmetic family, all expressed in the same formula language you already use, with no eval under the hood.
Named arguments, cleanly
The formula grammar now supports named arguments using =, which lets a single function call carry a partition key, a sort order, or a unit without any ambiguity with the existing ternary operator:
sum(Sales, by=Region)
cumsum(Sales, by=Region, order=OrderDate)
rank(Sales, desc=true)
datediff(OrderDate, ShipDate, unit="day")
Every formula you've already written keeps working exactly as before — = was never a valid operator in a formula's argument list, so this is purely additive.
Grouped aggregates: level-of-detail without flattening your data
The classic BI problem: you want SUM(Sales) computed per region, but you still need a row for every individual sale so you can divide by it, color by it, or plot it. That's a "fixed" or LOD expression in Tableau terms, and CanvasXpress's by= argument gives you exactly that behavior for any of its aggregate reducers (sum, mean, sd, median, count, min, max):
var config = {
graphType: "Bar",
calculatedFields: [
{ name: "RegionTotal", target: "variable", formula: "sum(Sales, by=Region)" },
{ name: "PctOfRegion", target: "variable", formula: "Sales / sum(Sales, by=Region)" }
]
};
var cx = new CanvasXpress("chartCanvas", data, config);
by= also accepts multiple keys — by=[Region, Year] — so you can fix an aggregate at whatever grain your analysis needs, and the result is rejoined back to every row that shares that key.
Table calculations: running totals, ranks, and moving averages
Alongside grouped aggregates, there's now a full family of ordered window functions: cumsum, cumprod, lag, lead, movavg, movsum, rank, denserank, pctchange, pcttotal, first, and last. Every one of them accepts by= to partition the calculation (say, per product line) and order= to control the sequence the calculation walks through — typically a date column:
var config = {
calculatedFields: [
{ name: "RunningTotal", target: "variable", formula: "cumsum(Sales, order=OrderDate)" },
{ name: "SalesRank", target: "variable", formula: "rank(Sales, desc=true)" },
{ name: "MoM", target: "variable", formula: "pctchange(Sales, order=OrderDate)" }
]
};
This is what turns a plain bar chart into a Pareto chart (sort descending, then cumsum and pcttotal to draw the cumulative line against the 80% threshold), or a plain line chart into a month-over-month trend. pctchange and pcttotal return a fraction rather than a pre-multiplied percentage, so they play correctly with axis formats that already show % — you won't end up with double-scaled numbers.
Date arithmetic that just works
Time intelligence — truncating a date to its month or quarter, computing the number of days between two dates, shifting a date forward, or pulling out a fiscal year — no longer requires pre-formatting your source data. The formula language now includes datetrunc, datediff, dateadd, year, quarter, month, week, day, weekday, hour, fiscalyear, and dateformat:
datetrunc(OrderDate, unit="month")
datediff(OrderDate, ShipDate, unit="day")
dateadd(OrderDate, 1, unit="year")
fiscalyear(OrderDate, start=7)
All date math runs in UTC, so there are no daylight-saving surprises, and datetrunc returns an ISO-formatted string (like 2026-03 for a month truncation), which means the result drops straight into CanvasXpress's existing date-aware rendering — it's automatically treated as a time value, not an opaque category.
Because the window functions and the date family share the same engine, you get the combination for free: order a cumsum by a truncated month, or partition a rank by fiscal year, without stitching together two separate tools.
Where you'll use it
Calculated fields built this way are available everywhere calculated fields already live: the calculated-field dialog (now with functions grouped into Math, Aggregate, Window, and Date categories with inline help), the right-click context menu, the Customizer Shelves, and Data Filters. Pickers for by= and order= are populated from your existing variable and sample annotations, so you're choosing from real columns rather than memorizing names.
One behavior worth knowing: calculated fields are materialized when the data loads, before any further aggregation or filtering. That means a pcttotal or rank reflects the full loaded dataset, not whatever subset is currently visible after an interactive filter — the same contract CanvasXpress's calculated fields have always had, just extended to the new functions.
Because this all lives inside the ordinary calculatedFields configuration, anything you build this way saves and reloads like any other chart: use Save as JSON from the toolbar to capture the chart (formulas included), drag the resulting file back onto a canvas to restore it, or use Reproduce to replay exactly how it was built.
Try it
If you've been exporting data to a spreadsheet to compute a running total or a year-over-year delta before charting it, that step is no longer necessary. Open the calculated-field dialog on any chart, pick a function from the Window or Date groups, and wire in a by=/order= pair — the chart does the rest.