How-to

How to create calculated fields with formulas in Hubviz

Create a new cube field from a formula, such as gross profit, margin or target status, and test the result on every row before you save.

Create a new column in the cube from a formula over the other fields, without touching the data source. Example: receita - custo becomes the Gross profit field.

When to use it

  • To compute a value row by row, such as profit, margin or an order’s total value.
  • To classify records, such as “Target met” and “Below target”, or late-payment bands.
  • To build text or a date from other fields, such as “Q1/2026” from the date.

The formula runs on each row of the cube, looking only at the fields of that row. It doesn’t sum or average across rows. For that, use measures on top of the calculated field.

Before you start, choose the cube fields on the Field Mapping tab. See Cube fields.

Create the field

  1. In the project side menu, open Cubes and click the cube.

  2. Open the Field Mapping tab and click Add Calculated Field. The New Calculated Field window opens.

  3. Fill in User Friendly Name, such as “Gross profit”. The technical name (gross_profit) is created from it.

  4. If you want, explain the calculation in Description.

  5. Click the formula editor (Construtor de Fórmulas in the product, the Formula Builder) and write the formula. When you click the editor, a panel with fields and functions opens beside it. Click an item to insert it. You can also type and pick from the suggestion list.

  6. Check the Resultado (Result) line right below the editor. It uses the first row of the cube data.

  7. To test on every row, click the speedometer icon in the example data section (Test formula on all rows). If any row fails, the Formula Errors button shows up at the bottom left.

  8. Click Save.

  9. Adjust the field type in the table and save the cube with Ctrl + S (see the next section).

Adjust the type after saving

The calculated field joins the cube checked, in the table of the Field Mapping tab. It starts with the Value type and the Text format, whatever the formula. Change them:

Formula resultField typeValue format
Number (profit, quantity)ValueNumber, Decimal or Currency
Text (status, band)CategoryText
DateDateDate

To edit or delete the field, use Edit Calculated Field and Delete Calculated Field in the Actions column of its row.

How to write the formula

ElementHow to write itExample
FieldThe technical name from the Field Name column of the mapping table, with no quotesreceita
NumberWith a decimal point0.15
Fixed textIn single quotes'Target met'
Math+, -, *, / and parentheses(receita - custo) / receita
Comparisons==, !=, >, <, >=, <=receita >= meta
FunctionsName in capitals, arguments in parentheses, separated by commasROUND(receita, 2)
  • Use == to compare, as the editor suggests.
  • To combine conditions, use AND(...), OR(...) and NOT(...).
  • To insert a field without mistyping its name, click it in the Campos panel.
  • When the cube is processed, an empty field counts as 0, and text that looks like a number ("150.50") is read as a number.

Functions

Functions live in the Matemática, Texto, Data and Lógica tabs of the panel. When you type a name, the editor shows the parameters.

GroupFunctionWhat it does
LogicIF(condition, if_true, if_false)Picks between two values.
LogicIFS(cond1, value1, cond2, value2, ...)Several conditions in sequence. End with true, value for the remaining case.
LogicIFERROR(value, value_if_error)Replaces an error or a division by zero with another value.
LogicIFEMPTY(value, value_if_empty)Replaces empty text with another value.
LogicSWITCH(expression, case1, res1, ..., default)Compares with each case. With no matching case and no default, it errors.
LogicAND(...), OR(...), NOT(value)Combine conditions.
MathAVG(n1, n2, ...), MAX(...), MIN(...)Average, largest and smallest among the values in this row.
MathROUND(n, places)Rounds. Without places, rounds to an integer.
MathCEIL(n), FLOOR(n), INT(n), ABS(n)Round up, round down, drop the decimal part, absolute value.
MathRANDBETWEEN(low, high)Random integer. It changes at every processing.
MathVALUE(text)Converts text to a number. Accepts a decimal comma.
TextCONCAT(t1, t2, ...)Joins text and numbers.
TextLEFT(text, n), RIGHT(text, n), MID(text, start, n)A piece of the text. The start position of MID begins at 1.
TextUPPER(text), LOWER(text), TRIM(text), LEN(text)Uppercase, lowercase, trim the ends, count characters.
TextREPLACE(text, old, new)Replaces every occurrence.
TextSUBFIELD(text, separator, position)A part of the text split by the separator. The position begins at 1.
DateDATE(year, month, day)Builds a date.
DatePARSE_DATE(text, format)Converts text to a date. The format is optional, such as 'dd/MM/yyyy'.
DateTODAY(), NOW()Today’s date, and the current date and time.
DateADD_DAYS(date, n), ADD_MONTHS(date, n), ADD_YEARS(date, n)Adds days, months or years. Use a negative number to subtract.
DateDAYS_BETWEEN(d1, d2), MONTHS_BETWEEN(d1, d2), YEARS_BETWEEN(d1, d2)Difference between two dates.
DateYEAR(date), MONTH(date), DAY(date), HOUR(date), MINUTE(date)A part of the date.
DateWEEKDAY(date), WEEKNUMBER(date)Day of the week (1 is Monday, 7 is Sunday) and week number.
DateDATE_ONLY(date, format)The date as text, without the time. The format is optional and defaults to dd/MM/yyyy.

Examples with the Sales cube

Calculated fieldFormulaResult on the first rowType
Gross profitreceita - custo499451Value, Number
Margin (%)ROUND((receita - custo) / receita * 100, 1)32.7Value, Decimal
Target statusIF(receita >= meta, 'Target met', 'Below target')Below targetCategory, Text
QuarterCONCAT('Q', CEIL(MONTH(data) / 3), '/', YEAR(data))Q1/2026Category, Text
Safe marginIFERROR((receita - custo) / receita, 0)0.327Value, Decimal

A banding with IFS:

IFS(dias_atraso > 60, 'Critical', dias_atraso > 30, 'Warning', true, 'On time')

Test the formula

The example data sits in a section below the editor, with row 1 of the cube.

ControlWhat it does
Resultado lineShows the formula’s value for the example row, or the error message.
Refresh iconFetches the example data from the source again.
Speedometer icon, Test formula on all rowsRuns the formula on every row read and shows each result, such as Linha 1: 499451.
Example dataThe JSON is editable. Change a value to see how the formula reacts to a specific case.
Formula ErrorsLists the rows that failed, with the message and the variables used. Shows up to 200 rows. Click one to see that row’s data.

Messages and limits

MessageCause and fix
Please fill in all required fields.The User Friendly Name is empty.
The formula cannot be empty.Write a formula before saving.
Waiting for data to load…The editor has no example data yet. Check that the cube read the source, or click the refresh icon.
Undefined symbol …The formula names something that is neither a field nor a function. Check the name in the Field Name column.
Fórmula inválida: …Shows up when the cube is processed (the text is in Portuguese in the product). The formula has a syntax error, such as an unclosed parenthesis.
No query to execute.The cube has no connection yet. The editor needs one to fetch the example.
Are you sure you want to exit without saving changes?You closed the window with unsaved changes.
  • A calculated field only sees the fields of its own cube, including relationship fields.
  • Use IFS with true at the end. Without it, rows that match no condition stay empty.

Next steps

  • Adjust the new field’s type in Cube fields.
  • Summarize the field with measures, such as the sum of Gross profit per month.