Formula: Count Relations

Formula: Count Relations

Published
May 1, 2023
Author

Beli Löw

Lecture
2 min

← All Articles

image
icon
In brief:

There are two easy ways to count linked entries:

  1. With a formula.
  2. By setting a rollup on the link and counting the entries.

Counting Linked Entries with a Formula

You can also display the property as a “Page Section.” To do this, click on Show asPage Section for the property.

To count how many entries are linked from a relation, you can use the following formula.

Simply put: The formula counts the number of commas , between the entries.

In this example, we want to calculate the occupancy of office rooms based on the linked employees, which are sourced from the employee database.

Basierend auf den verknüpften Mitarbeitenden, kann die Anzahl berechnet werden.
Basierend auf den verknüpften Mitarbeitenden, kann die Anzahl berechnet werden.
Extract from the employee database showing which room the person is assigned to.
Extract from the employee database showing which room the person is assigned to.
icon
How it works

You need the following database fields to perform the calculation.

Capacity - Type: Number for the room's capacity

Employees - Type: Relation to the employee database

Number of Employees - Type: Formula to calculate the linked employees

if(not empty(
		prop("Mitarbeitende")), length(replaceAll(prop("Mitarbeitende"), "[^,]", "")) + 1, 0
	)

Free Spaces - Type: Formula For calculation Capacity - Number of Employees

prop("Kapazität") - prop("Anzahl MA")

Counting linked entries with a rollup.

icon
How it works

Add a rollup to the existing relation and count the entries.

  1. Create Rollup on existing relation
  2. image
  3. For Calculate, select Count All
  4. image

Questions about the formulas? Feel free to send us an email at hi@notioneers.ch.

icon
image

Beli Löw

Beli is an IT project manager, tool enthusiast, entrepreneur and has organized his whole life with Notion. His news sources are release notes from tools. There is (almost) no feature or shortcut that he does not know.

image

Join us Today: and become a Notion know-all

Wouldn’t you like to know more?

Keep Reading…