Calculate with formulas, running totals and ranks
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

Step 1 of 5: Open Math Function
Write the calculation in SQL mode
- Click Describe what you want to generate and type what you want, for example "revenue after a 15% discount".
- Click Generate. Mammoth writes a SQL expression into the SQL Expression editor. Review or edit it, or type SQL there yourself.
- 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.
- 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.
| Where | What you write | Example |
|---|---|---|
| Math Function, SQL mode | An expression that returns a number for each row; the result is always stored as a number | ROUND("price" * 1.2, 2) |
| Conditional Filter, SQL mode | A 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.
| Formula | Result |
|---|---|
"unit_price" * "quantity_sold" | Line revenue per row |
("actual" - "target") / "target" * 100 | Percentage variance against target |
INT("total_revenue" / 12) | Monthly average with the decimals dropped |
"revenue" / SUM("revenue") * 100 | Each 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.
Related
- Math Function formula syntax and messages: functions, parameters and every validation message.
- Add a running total, rank or largest value: Window function and Obtain Large or Small Values.
- Work with dates and financial years: the Date Tools in the same category.
- Parameters and snippets: values you reuse across formulas.
Something wrong? support@mammoth.io

