# Baserow Formula Functions - Syntax Reference and Examples

> See how Baserow formulas handle linked tables, dates, and text arrays, plus ready-made patterns for math, conditions, and lookup aggregation.

Source: https://opennix.org/en/docs/baserow/formula/understanding-formulas/


Baserow ships a built-in formula editor with autocomplete and dozens of functions for calculations, text work, dates, and linked-table lookups. This article covers the syntax for complex field types, a set of ready-to-use formula patterns for everyday tasks, and answers to common questions about arrays, durations, and empty values.

## Overview

Baserow formulas work with most field types, including [duration fields](/docs/baserow/field-types/duration-field/) and [multiple select fields](/docs/baserow/field-types/multiple-select-field/). A single expression can run math, manipulate text, calculate dates, and build logical comparisons.

If you want records to name themselves automatically - `Invoice-001` or `Sprint-Dec`, for example - turn the [primary field](/docs/baserow/fields/primary-field/) into a formula field. The row name then recalculates on its own whenever the underlying data changes.

### Finding functions

The formula editor surfaces autocomplete and function suggestions as you type, each one showing its syntax and a usage example.

To find the function you need:

1. Create or open a formula field for editing;
2. Start typing inside the formula editor;
3. Scan the list of suggested functions and their descriptions;
4. Click a function to see its full syntax and an example.

## Working with complex field types

Formulas treat simple and composite fields differently. The three cases below cause most of the confusion.

### Multiple select fields

Formulas can work with [multiple select fields](/docs/baserow/field-types/multiple-select-field/): check which options are selected on a row and run operations against that set of values.

![Multiple select support in the formula field](/images/baserow/formula/understanding-formulas-multiple-select-support.png)

### Link to table fields

For [link to table fields](/docs/baserow/field-types/link-to-table-field/), use `lookup()` to pull field values from linked rows, then wrap the result in an aggregation function such as `sum()`, `count()`, or `join()`.

### Lookup and rollup fields

[Lookup fields](/docs/baserow/field-types/lookup-field/) and [rollup fields](/docs/baserow/field-types/rollup-field/) return arrays of values rather than a single number or string. Convert the array to a single value with an aggregation function before using it in a condition or comparison.

## Common formula patterns

The patterns below cover most everyday tasks. Swap the field names in each example for fields in your own table.

### Calculations and math

Calculate a line total:

```
[Quantity] * [Unit Price]
```

Apply a percentage discount:

```
[Price] * (1 - [Discount Percent] / 100)
```

Round to two decimal places:

```
round([Amount], 2)
```

Find the larger of two values:

```
greatest([Value A], [Value B])
```

### Text operations

Combine a first and last name:

```
concat([First Name], ' ', [Last Name])
```

Convert text to uppercase:

```
upper([Product Code])
```

Extract the first 10 characters:

```
left([Description], 10)
```

Check whether text contains a word:

```
contains([Notes], 'urgent')
```

### Date and time

Calculate the number of days between two dates:

```
date_diff('day', [Start Date], [End Date])
```

Format a date as text:

```
datetime_format([Created], 'YYYY-MM-DD')
```

Check whether a date is already in the past:

```
[Due Date] < today()
```

Pull the year out of a date:

```
year([Date Field])
```

### Conditional logic

Show different text depending on status:

```
if([Status] = 'Complete', 'Done', 'Pending')
```

Fall back to a default value when a field is empty:

```
when_empty([Notes], 'No notes added')
```

Combine several conditions:

```
if(and([Quantity] > 0, [Price] > 100), 'In Stock - Premium', 'Standard')
```

### Working with linked tables

Sum values pulled from linked rows:

```
sum(lookup('Orders', 'Total'))
```

Count linked items:

```
count([Related Items])
```

Join text from several linked rows:

```
join(lookup('Projects', 'Name'), ', ')
```

Filter, then sum the result:

```
sum(filter(lookup('Items', 'Price'), lookup('Items', 'Status') = 'Active'))
```

### Creating interactive buttons

Build a clickable button:

```
button('https://example.com/' + [ID], 'View Details')
```

Turn a value into a mailto link:

```
link('mailto:' + [Email])
```

![Formula-driven buttons in Baserow](/images/baserow/formula/understanding-formulas-formula-buttons.png)

## Frequently asked questions

**Why isn't my formula working with a lookup or link-to-table field?** Lookup and link-to-table fields hold arrays - several values at once - not a single value, and most functions expect one value as input. Wrap the field in an aggregation function such as `sum()`, `join()`, `count()`, or `avg()` to turn the array into a single value first. For example, `isblank([Organization])` fails if Organization is a link field, but `isblank(join([Organization], ''))` converts the array to text before checking it.

**Can I use formulas with duration fields?** Yes. [Duration fields](/docs/baserow/field-types/duration-field/) support math operations directly - add, subtract, multiply, and divide them just like ordinary numbers.

**How do I check whether a date falls on a specific day of the week?** Use `datetime_format()` with the `D` format code, where Sunday equals 1, Monday equals 2, and so on: `datetime_format([Date Field], 'D') = '1'` returns true for a Sunday. For the full list of formatting codes, see the [PostgreSQL formatting documentation](https://www.postgresql.org/docs/current/functions-formatting.html).

**Do today() and now() update automatically?** Yes, both functions refresh roughly every 10 minutes. Use `today()` when you only need the date, and `now()` when you need the date and time together. The 10-minute interval is a best-effort target rather than a guarantee - a workspace that has been idle for a while may only refresh once every 60 minutes.

**How do I handle empty or null values in a formula?** Use `when_empty()` to supply a fallback value, or `isblank()` to test whether a field is empty: `when_empty([Optional Field], 'Default Value')` or `if(isblank([Name]), 'No name provided', [Name])`.

**Can I use regular expressions inside a formula?** Yes, `regex_replace()` finds and replaces text by pattern: `regex_replace([Phone], '[^0-9]', '')` strips every non-numeric character out of a phone number.

## What's next

New to formula fields? Start with the [Formula field overview](/docs/baserow/formula/formula-field-overview/) for a general introduction. To go deeper on the field types formulas lean on most, read [Link to table field](/docs/baserow/field-types/link-to-table-field/), [Lookup field](/docs/baserow/field-types/lookup-field/), [Rollup field](/docs/baserow/field-types/rollup-field/), and [Working with timezones](/docs/baserow/fields/working-with-timezones/) for date math across time zones. From there, move on to [Views](/docs/baserow/views/) to see how formula output drives filtering and sorting.

