# Value maps and calculated fields

> **Early release.** This feature is in early release, so its screens and behavior may change. Tell us what you think with **Send feedback**. See [Early release features and Send feedback](https://docs.reportworq.com/reporting-guide/50-early-release/early-release-features-and-send-feedback.md).

A view can reshape its values without a SQL view. A **value map** turns a field's values into other values: status codes into labels, `1` and `0` into **Yes** and **No**, amounts into bands. A **calculated field** is a new field worked out for each row from the view's other fields, such as `[Amount] * [Quantity]` or `IF(ISBLANK([Region]), "None", [Region])`.

Both run in Reportworq after the data is read, the same way for every source: SQL databases, Planning Analytics, the planning-tool APIs and workspace files. Every report that uses the view sees the result: **Preview**, the Excel add-in, web reports and distribution jobs.

**When to use them.** Say a `status` column holds the codes `O`, `P` and `V`. A value map shows them as **Open**, **Paid** and **Void**, so no report repeats the lookup. A calculated field **Net per Unit** of `[Net Sales] / [Quantity]` saves every report author the same formula. Use a SQL view instead when you need totals, a union, or a join the designer does not offer; see [Build a view](https://docs.reportworq.com/reporting-guide/10-data-modeling/build-a-view.md).

## Before you start

- You can edit the data model, and the view has a **Fields** tab.
- A value map needs a **mapped** field (the green **mapped** chip). A calculated field reads other fields of the same view by their names.

## Map a field's values

1. Open the data model, select the view in the rail, and select its **Fields** tab.
2. On the field's row, select the value map button (two arrows). Its tooltip reads **Value map**. The **Value map** panel opens at the side, titled with the field's name.
3. Select **Add rule**, choose how the rule matches, and type what a matching value **Shows as**:
   - **Equals**: the value equals the one you type. Numbers compare as numbers, so `1` matches `1.0`.
   - **In list**: the value equals any of the values you type, separated by commas.
   - **Starts with**: the value's text starts with what you type.
   - **Number range**: the value is a number from **From** up to **To**. **From** is included and **To** is not, so `0` to `100` and `100` to `500` never overlap. Leave one end empty for no limit.
4. Add more rules as needed. Rules run from the top, and the first rule that matches gives the value shown. Use the arrows to move a rule up or down, and the bin to remove it.
5. Under **Anything else**, choose **Keep the original** to leave other values as they are, or **Show a value** to show one value for all of them, for example `Other`.
6. To show something for an empty value, tick **Show a value for null or blank** and type it, for example `(none)`. Without it, an empty value stays empty and no rule applies to it.
7. Text compares without regard to case, so `yes` matches `Yes`. Tick **Match case** to compare case exactly.
8. Check the **Sample** row: it shows the field's sample value and what it shows as now. Select **Done**, then **Save Changes**.

**Yes / No preset.** Select **Yes / No preset** to set two rules at once: `1` or `true` shows **Yes**, and `0` or `false` shows **No**. It replaces any rules already there. Change the labels in **Shows as** if you want other words, such as **Active** and **Inactive**.

A field with a value map shows a filled value map button, and its sample on the **Fields** tab shows the mapped value. To take the map off, open the panel and select **Remove value map**.

A mapped field's values are text, whatever type the source column has. A value map runs after the field's **Type and format**, so it sees the value that setting produced.

## Add a calculated field

1. On the view's **Fields** tab, select **Add field**, then **Calculated field…**. A field named **Calculation** is added, and the **Calculated field** panel opens.
2. Type a **Name**. It must be unique within the view.
3. Choose the **Result type**: **String**, **Number**, **Date** or **Boolean**. Each result is converted to that type, so a report gets a real number or date.
4. Type the **Expression**. Select a field's button under **Fields** to add it to the end of the expression as `[Field name]`.
5. Watch the message under the expression. **Valid** shows the result for the sample row. **Not valid yet** says what is wrong, such as `The expression ends too soon.` or `It reads [Regon], and the view has no field called that.`
6. Select **Done**, then **Save Changes**. Check the result on the **Preview** tab.

On the **Fields** tab, a calculated field shows its expression where other fields show their source column, with a calculator icon. Select it to edit the calculation. If the field cannot be worked out, it shows a warning icon, and its tooltip says why.

### Writing an expression

| You write | It means |
|---|---|
| `[Net Sales]` | The value of the field **Net Sales** in the same row. Names ignore case. |
| `"Open"`, `12.5`, `TRUE`, `FALSE` | Text (in double quotes; write `""` for a quote inside), a number, true and false. |
| `+ - * /` | Arithmetic. Text that reads as a number, such as `"12"` or `"-3.5"`, counts as a number: a period is the decimal point and there are no thousands separators, so `"1,5"` and `"1,234"` are text. The same rule holds for comparisons and true-or-false tests. |
| `&` | Joins text: `[First] & " " & [Last]`. An empty value joins as nothing. |
| `= <> < <= > >=` | Compare two values. Numbers compare as numbers, dates as dates, text ignoring case. `!=` also works for `<>`. |
| `IF(test, then, else)` | `then` when `test` is true, otherwise `else` (empty if you leave it out). An empty test counts as false. |
| `COALESCE(a, b, …)` | The first value that is not empty. |
| `ISBLANK(a)` | True when `a` is empty or only spaces. |
| `AND(a, b, …)`, `OR(a, b, …)`, `NOT(a)` | Combine true and false values. |
| `TODAY()` | Today's date. |
| `LEFT(text, n)`, `RIGHT(text, n)` | The first or last `n` characters of the text. |
| `MID(text, start, n)` | `n` characters from position `start`, counting the first character as 1. |
| `LEN(text)` | The number of characters. |
| `UPPER(text)`, `LOWER(text)`, `TRIM(text)` | The text in capitals, in lower case, or without spaces at either end. |
| `TEXT(value, format)` | A date or number written with a .NET format string: `TEXT([Created], "yyyy-MM")` gives `2026-11`, `TEXT([Amount], "N2")` gives `1,234.50`. The format is at most 50 characters. |
| `YEAR(date)`, `MONTH(date)`, `DAY(date)` | The year, month (1 to 12) or day of the month, as a number. |
| `HOUR(date)`, `MINUTE(date)` | The hour (0 to 23) or minute (0 to 59) of a date and time, as a number. A date with no time gives 0. |
| `DATE(year, month, day)` | The date with those parts, such as `DATE([Year], 12, 31)`. |
| A date `+` or `-` a number | The date that many days later or earlier. One date minus another gives the days between them. |

A date written as text in the ISO form, such as `2026-11-18` or `2026-11-18T09:30:00`, counts as a date for `YEAR`, `MONTH`, `DAY`, `HOUR`, `MINUTE` and `TEXT`. Its time is the time as written: for `2026-07-31T21:30:00-04:00`, `HOUR` gives 21 whatever the server's time zone. Each text and date function gives an empty value for an empty value.

Multiplication and division come before addition and subtraction, then `&`, then comparisons, as in Excel. Use parentheses to change the order: `([Price] - [Cost]) * [Quantity]`.

`+` adds numbers only. To join text, use `&`; in a row where `[Code] + 1` meets the text `A7`, the value is empty and the run's warning gives the reason, `+ adds numbers, and the text "A7" isn't one. Use & to join text.`

### What a calculation sees

- **The shown values.** A calculation reads each field after its **Type and format** and its value map. If **Status** maps `P` to **Paid**, write `IF([Status] = "Paid", [Amount], 0)`.
- **Other calculated fields.** A calculated field can read another one. Reportworq works them out in the right order, whatever their order on the **Fields** tab.
- **Hidden fields.** A hidden field can feed a calculation. Hide `Quantity` and still show `[Amount] * [Quantity]`.
- **Empty values.** Arithmetic or a comparison with an empty value gives an empty result. Use `COALESCE([Discount], 0)` to treat an empty value as zero.

### When a value cannot be worked out

- **A row:** when one row's value cannot be worked out (a division by zero, text in arithmetic, a result too large to calculate with, a result that does not convert to the result type), that cell is empty, and the run adds one warning for the field, `Some values of 'Net per Unit' couldn't be calculated`, which counts the empty rows and gives the first reason.
- **The whole field:** when the expression cannot be read, reads a field the view does not have or an unmapped field, reads itself, or two calculated fields read each other, every value of the field is empty, and the run adds the warning `Calculated field 'Net per Unit' can't be calculated` with the reason.

## Filters on these fields

A filter on a field with a value map or a calculation sees the **shown** value. If `status` maps `O` to **Open**, filter it on `= Open`, not on `= O`. Reportworq applies such a filter after it works out the values, in memory, never in the source's query.

A filter on any other field, including a field that has only a **Type and format**, compares the **source** value, as it always has, and runs at the source wherever the source can filter. See [Field filtering](https://docs.reportworq.com/reporting-guide/10-data-modeling/field-filtering.md#where-filters-run).

## The order Reportworq applies them in

For each view, Reportworq reads the source (with the filters the source can run) and then, in this order:

1. Applies the filters on source values that could not run at the source.
2. Applies each field's **Type and format**.
3. Applies each field's value map.
4. Works out the calculated fields, each after the fields it reads.
5. Applies the filters on value-mapped and calculated fields.
6. Sorts the fields into their order, drops hidden fields, and names the columns.

Two fields can show the same source column in different ways, for example `status` as the raw code and, in a second field, mapped to a label.

## Notes and limits

- **Renaming a field does not change expressions that read it.** After a rename, the calculated field shows the warning icon; open it and change the name in the expression.
- **An empty value can default to a number or a date.** In a field's **Type and format**, **Null / blank shows as** on a **Number**, **Date** or **Boolean** field now gives that type when the text reads as one: `0` is the number 0, so a calculation can add it and a report can total it. Text that does not read as one, such as `n/a`, stays text.
- **A value map has no "contains" or pattern rule.** Use **Starts with**, or a calculated field with `IF`.
- **Calculations run row by row.** There are no totals, running sums or lookups to other rows; use a SQL view for those.
- **An older Reportworq server ignores both features.** A data model saved with them still opens on a server that does not have them: the value map is not applied, and a calculated field appears as an unmapped field with no values.

> **Going deeper.** For the **Fields** tab in full, see [Data models](https://docs.reportworq.com/reporting-guide/10-data-modeling/data-models.md#curate-the-fields). For filters and where they run, see [Field filtering](https://docs.reportworq.com/reporting-guide/10-data-modeling/field-filtering.md).

Source: https://docs.reportworq.com/reporting-guide/10-data-modeling/value-maps-and-calculated-fields.html
