# Computed Fields

**Computed Fields** automatically create their own value based on the information stored in other Fields within a Record. They are especially useful for performing calculations within a Collection and work similarly to Excel spreadsheet commands.

## How to Create a Computed Field

### Accessing Computed Fields

Computed fields are accessed in the same way as regular fields. You can see how to Configure fields here.

- Choose a collection to configure from your Sidebar.
- Open the options menu (⋯) in your Toolbar, at the top right of your screen. Select “Configure” from the available options.

- In the fields pane of your collection configuration page, you will see a list of all fields within the current collection.
- Click "Add Field".
- Open the dropdown list of options beneath “TYPE”. You can either search for “Computed” or scroll through the first column to find it.

- Once you have selected “Computed”, Kinabase will provide the following Computed Field options:

**Computed (Text)**:

Text that can include other fields in the record using a template.

**Computed (Number)**:

A number that is calculated from other fields in the record using a formula.

**Computed (Date)**:

A date that is calculated from other fields in the record using a formula.

**Lookup**:

A field that copies its value from another record in a linked collection.

**Aggregation**:

A number that is calculated from records in a linked collection.

- You can choose the appropriate field type based on your needs.

### How to get your computed field to access the other fields in your collection

To create a new value in your computed field, you need to specify which other fields it should access. These instructions go into the “TEMPLATE” section.

Field values are accessed by using the “$” symbol, followed by the field name in ALL CAPS. Spaces in field names are replaced by underscores.

**Example:** For a field called "First Name", you would type `$FIRST_NAME`

into your template:

### Subfields

Some field types have extra values stored in "subfields". You can access and display these values by typing the `$FIELD_NAME`

, followed by the `SUBFIELD_NAME`

, seperated by a full stop (`$FIELD_NAME.SUBFIELD_NAME`

).

This is useful when you want to extract specific information from a field, such as the postcode from an address field.

Here are some of the subfields we have on Kinabase:

- Location field -
`TITLE`

,`LINE_1`

,`LINE_2`

,`CITY`

,`COUNTY`

,`COUNTRY`

,`POSTCODE`

,`LAT`

,`LNG`

- Date range -
`START`

,`END`

,`DURATION`

,`ACTUAL_START`

,`ACTUAL_END`

- Risk score -
`IMPACT`

,`LIKELIHOOD`

**Example:**

The instructions above would create the following record:

### Mathematical functions

You can use basic maths operator (`+ - * /`

and brackets) when creating a computed field. Be sure to include a space on either side of an operator.

### Numbers with units

You can add units to constant numbers and use them in calculations. Units can be combined with `*`

and `/`

(this time without spaces). Kinabase understands a wide range of units, including SI units, time, and currency, and will automatically convert between them.

**Example:** For a mileage field (stored in miles), a formula of `$MILEAGE * £3.50/mi`

would give you your new value in pounds (£).

Here are some more examples of what this might look like:

`45m3`

- 45 cubic metres`70mi/h`

- 70 miles per hour`30deg`

- 30 degrees (angle)

## Full list of units

Below is a full list of units supported in Kinabase.

### SI Base Units

Unit | Description | Symbol |
---|---|---|

Metre | Length | `m` |

Kilogram | Mass | `kg` |

Second | Time | `s` |

Ampere | Electrical Current | `A` |

Kelvin | Temperature measured from absolute zero | `K` |

Mole | Amount of substance | `mol` |

Candela | Luminosity | `cad` |

Byte | Amount of data (note: `1kB = 1000B` ) | `B` |

All of the units above can be used, except for Kilograms and Seconds in some specific cases.

### Additional time units

Unit | Description | Symbol |
---|---|---|

Minute | 60 seconds | `min` |

Hour | 60 minutes, 3600 seconds | `h` |

Day | 24 hours | `d` |

### Additional mass units

Unit | Description | Symbol |
---|---|---|

Gram | 0.001 kg | `g` |

Tonne | 1000 kg | `t` |

### Dimensionless units

Unit | Description | Symbol |
---|---|---|

Radians | Angle (2π in a full revolution) | `rad` |

Degrees | Angle (360 in a full revolution) | `deg` |

Percentage | Proportion, 1 / 100 | `%` |

Parts per million | Proportion, 1 / 1,000,000 | `ppm` |

### Temperature

Unit | Description | Symbol |
---|---|---|

Celcius | Temperature measured from freezing point of water | `degC` |

### Common UK Units

Unit | Description | Symbol |
---|---|---|

Miles | Distance, = 1609.344 m | `mi` |

Pints | Volume, = 568.26 ml | `pt` |

Pounds Sterling | UK Currency | `£` |

### Area

Unit | Description | Symbol |
---|---|---|

Hectare | 10,000 square metres (100m × 100m) | `ha` |

Square Kilometres | 1,000,000 square metres (1km × 1km) | `km2` |

Square Centimetres | 1cm × 1cm | `cm2` |

### Volume

Unit | Description | Symbol |
---|---|---|

Litre | Volume of 10cm cube, 0.001 cubic metres | `l` |

Millilitre | 0.001 litres | `ml` |

## If function

Conditional logic is possible through the IF function, which follows this syntax:

`IF([condition], [result if true], [result if false])`

**Example:** `IF($COST > £4, $COST * 2, $COST * 2.5)`

would either:

- Multiply the cost by 2 if the cost exceeds £4.00, or
- Multiply it by 2.5 if the cost is less than or equal to £4.00.

This could also be simplified as `$COST * IF($COST > £4, 1.5, 2.5)`

.

### Conditions

#### Numerical

`=`

- Equals`!=`

- Does not equal`>`

,`<`

- Greater than, less than`>=`

,`<=`

- Greater than or equal to, less than or equal to

#### Text

`is blank`

- Field is empty (e.g.`$NAME is blank`

)`matches`

- Equality (e.g.`$NAME matches "John"`

)`contains`

,`starts with`

,`ends with`

#### Date + Time

`is in`

- Matches, considering precision (e.g.`$START_DATE is in 2024`

)`is before`

,`is after`

#### Combining

`not ...`

- Inverts result (e.g.`not $LENGTH > 1m`

is equivalent to`$LENGTH <= 1m`

)`... and ...`

- True if both sides are true (can be chained)

(e.g. `$LENGTH > 1m and $WIDTH > 1m and $HEIGHT > 1m`

)

`... or ...`

- True if either side is true (can also be chained)

(e.g `$LENGTH > 1m or $WIDTH > 1m or $HEIGHT > 1m`

is True if any dimension exceeds 1 metre)

`... xor ...`

- Exclusive, or True if either side is true but not both

## Handling Empty Values

If a field is left empty (null), operations involving that field will return empty (null). To fall back to a default value, use the coalescing operator `??`

.

**Syntax:** `[value to check] ?? [fallback value]`

**Example:** `$PROFIT ?? ($INCOME * 10%)`

will return the “Profit” if available, or calculate 10% of the “Income” if not.

### Computed Text Fields

Computed Text Fields use the same method to access field values, but they insert values into a template instead of calculating them.

**Example:** `This apple is a $TYPE and tastes $REVIEW`

could display as: "This apple is a Granny Smith and tastes Amazing".

There are a few special cases for this formatting:

- Adding a second $ ends the accessor early.

**Example:** `This fruit is a $TYPE$FRUIT`

could display as: "This fruit is a GRAPEFRUIT"

- To insert an actual dollar symbol, use
`$$`

.

**Example:** `This $TYPE apple costs $$3.00`

could display as: "This Braeburn apple costs $3.00".