ERP expressions — Quick user guide
Practical reference for the expression language (reports, calculated columns, conditions). For the full specification: GRAMATICA.md.
The basics
| I want... | I type | Result |
|---|---|---|
| A field from the row | [Importe] · [Total Línea] | its value |
| A precalculated total | AGG(baseImponible) | its value |
| Arithmetic | [Cantidad] * [Precio] * 1.21 | number |
| Text | "Cliente: " + [Nombre] | text |
| A condition | [Importe] > 1000 ? "VIP" : "normal" | one of the two branches |
| The same, in Python style | "VIP" if [Importe] > 1000 else "normal" | identical |
| Default value if it is empty | [Descuento] ?? 0 | the first non-empty one |
| A fixed date | #2026-06-10# · #2026-06-10 14:30# | date |
- Numbers always with a decimal point:
1.21(the comma isn’t valid when writing the expression; results are shown in Spanish format). - Capitals and lower case make no difference in names:
[importe],Upper(...),UPPER(...). - Comparing is done with
==(writing=gives an error that reminds you). Also:!=or<>,<,<=,>,>=. - Conditions:
&&/||/!or, if you prefer,and/or/not. - If you come from Python:
value if condition else otherandNone(=null) also work. The comment is//(not#: that one is for dates#2026-06-10#).
Empty values (null): it behaves like the database
- Any operation with an empty value gives an empty value:
[Descuento] + 5→ empty if there is no discount. Fix:([Descuento] ?? 0) + 5orCoalesce([Descuento], 0). - Asking whether it is empty:
[Fecha2] == null(this one does give true/false). - An empty condition counts as false:
IIf([X] > 5, "a", "b")gives"b"if X is empty. Concat("a", [Nulo], "b")ignores empty values →"ab"(+doesn’t: it would give empty).
Most used functions
| Function | Example | Gives |
|---|---|---|
Round(x, decimals) | Round([Importe] * 1.21, 2) | 121.00 |
Abs · Floor · Ceiling | Ceiling(2.1) | 3 |
Min(a, b) · Max(a, b) | Max([Stock], 0) | |
Upper · Lower · Trim | Upper([Nombre]) | "ACME" |
Len(s) | Len([NIF]) | 9 |
Substring(s, start, length) | Substring([NIF], 1, 1) (starts at 1!) | first letter |
Replace · PadLeft · PadRight | PadLeft([Num], 6, "0") | "000043" |
Contains · StartsWith · EndsWith | StartsWith([CP], "28") | true/false |
Today() · Now() | constant throughout the report | |
Year · Month · Day | Year([Fecha]) | 2026 |
AddDays · AddMonths · AddYears | AddDays([Fecha], 30) (due date) | date |
DateDiffDays(start, end) | DateDiffDays([Fecha], Today()) (age of the debt) | days |
IIf(cond, ifTrue, ifFalse) | IIf([Cantidad] > 0, [Importe]/[Cantidad], 0) | only evaluates the chosen branch |
Coalesce(a, b, ...) / IsNull(a, b) | Coalesce([Tarifa2], [Tarifa1], 0) | first non-empty |
Format(value, "format") | Format([Importe], "N2") · Format([Fecha], "dd/MM/yyyy") | text already formatted (Spanish) |
ToDecimal · ToString · ToDate | ToDecimal([CodigoTexto]) | explicit conversion |
Errors that warn you
Campo desconocido: [Cantida]. ¿Quiso decir Cantidad?— a typing mistake in a name.'=' no es un operador de comparación. Para comparar use '=='.Sin acceso al área Costes— the expression uses data that your profile can’t see.División por cero— protect yourself withIIf([Divisor] != 0, [X]/[Divisor], 0).
Scripts (advanced: automations and plugins)
Where the system allows it (not in reports), a sequence of statements ending in ;:
var total = 0;
foreach (var x in Lineas)
{
if (x > 10) { total = total + x; }
}
return total;
- Your own variables with
var; the data from the environment is read-only. if/else,while,foreach (var x in List),return value;.- Loops have a step limit: an infinite loop is cut off on its own with a clear error.
- Comments:
// lineand/* block */(they also work in expressions).