Skip to content
Learn › Clean and shape data: open the docs menu

Calculate with formulas, running totals and ranks

All plans · Project Editor or Project Admin · Updated 8 Nov 2026

The Numeric Tools in Describe your transformation › Date, Numeric & Text add calculated columns that re-run on every refresh. Math Function works out a value row by row from a SQL expression or a formula, and is covered here. Window function (running totals, ranks, row-to-row comparisons) and Obtain Large or Small Values (the Nth largest or smallest of several columns) are in Add a running total, rank or largest value.

Create a calculated column step by step

Describe your transformation menu on Date, Numeric & Text, with Math Function under Numeric Tools

Step 1 of 5: Open Math Function

Write the calculation in SQL mode

  1. Click Describe what you want to generate and type what you want, for example "revenue after a 15% discount".
  2. Click Generate. Mammoth writes a SQL expression into the SQL Expression editor. Review or edit it, or type SQL there yourself.
  3. If your description also says which rows to change ("double the price where region is Europe"), Mammoth puts that part into the step's row condition. Check it with the filter icon before you apply.
  4. To add a parameter, click Insert Parameter. It goes in at the cursor as {Discount_Rate}. Text and Date parameters are wrapped in single quotes ('{Region}') so they read as SQL strings.

Example: ROUND("unit_price" * "quantity_sold" * (1 - {Discount_Rate}), 2) uses a Number parameter and DuckDB's ROUND function.

Write SQL expressions in DuckDB SQL

Pipeline steps run on DuckDB, so Math Function's and Conditional Filter's SQL modes take DuckDB SQL and any DuckDB function, such as ROUND, COALESCE, CASE WHEN or DATE_DIFF. Put column names in double quotes and text values in single quotes.

WhereWhat you writeExample
Math Function, SQL modeAn expression that returns a number for each row; the result is always stored as a numberROUND("price" * 1.2, 2)
Conditional Filter, SQL modeA condition that is true for the rows to keep or remove"region" = 'Europe' AND "amount" > 100

A Conditional Filter's SQL doesn't read parameters; use Builder mode with the Parameter comparison type there. For a whole query across a View, use Write SQL with AI.

Write the calculation in Formula mode

Type a formula with column names in double quotes, the operators +, -, * and /, brackets and the built-in functions. The placeholder shows the shape: "Column1" + "Column2" or SUM("Column1") + INT("Column1"/10). An autocomplete list offers columns, functions and parameters as you type. A message under the formula says "Looks good" or names the problem. Every function and message: Math Function formula syntax and messages.

FormulaResult
"unit_price" * "quantity_sold"Line revenue per row
("actual" - "target") / "target" * 100Percentage variance against target
INT("total_revenue" / 12)Monthly average with the decimals dropped
"revenue" / SUM("revenue") * 100Each row's share of the total, in percent
"revenue" - AVG("revenue")Each row's distance from the average

Calculate only for rows that match a condition

Click the filter icon at the left of the Place in row. The condition dialog has the same AI prompt, Builder and SQL options as Conditional Filter (Filter rows). Rows that don't match keep their current value in an existing column, and stay empty in a new column.

Was this page helpful?

Something wrong? support@mammoth.io