Your Notion rollup is not a number (and how to do math on it)

In the previous article, we learned that people and relations come back as lists rather than text. Rollups have the same problem underneath, and it announces itself much more loudly. π―
This article is a part of the Fantastic Formulas series. This series features helpful articles about formulas in Notion.
A rollup set to Show original will happily display 1892 or 35% and still be a list. The moment you put it through *, /, -, or a date function like dateAdd, Notion stops you with something along the lines of Cannot call expression of type number or Cannot call dateSubtract with target of type array. The usual reflex is to wrap the whole thing in toNumber(), and that does nothing at all here, because a list is not a string with a number hiding inside it. π
Today we will walk through three fixes, in the order I would actually try them. As always I will work from a small database, and this time letβs say we are adding up invoice lines. β
1. Show original
In this database shown below, each invoice page relates to its line items, and the rollup is pulling Amount with Calculate set to Show original. β
Example - Rollup with Show original
Acme shows 1200, 450, which at least looks like a list. Northwind shows 1892, and that is the row that catches people out, because a list with one item in it is indistinguishable from a number until you try to multiply it.
2. Change Calculate to Sum
The quickest fix needs no formula at all. Open the rollup and set Calculate to Sum, or Max, Min, or Earliest date depending on what you are rolling up. Notion then hands you a real number or a real date. β
As you can see below, the column behaves differently π½
Show original vs Sum
Acme becomes 1650, Northwind still reads 1892 but is now genuinely a number, and Studio retainers settles at 0. Reach for this whenever you only need the total and you are not filtering the related rows on the way through. Keep Show original for the cases where you want to see the individual values, and do not try to do arithmetic on it there.
3. Unwrap it, or skip the rollup
If you cannot change Calculate, usually because something else in the database depends on seeing the original values, take one item out of the list yourself.
prop("Line amounts").at(0).toNumber()
First item of a rollup, as a number
.at(0) and .first() do the same job. Once you are holding a single value rather than a list, toNumber() has something it can work with.
Better still, skip the rollup entirely and read the relation from inside the formula. This is the Formulas 2.0 answer to most rollup problems. β
prop("Lines").map(current.prop("Amount")).sum()
Sum related amounts without a rollup
Say we want 18% tax on that total. Here is the version that throws if the rollup is still on Show original:
prop("Line amounts") * 0.18
Broken tax formula
And here is the one that works, either on a Sum rollup or on the map().sum() formula above:
if(empty(prop("Total")), empty(), prop("Total") * 0.18)
Tax on a real number, blank when there is no total
As you can see below, the difference is hard to miss π½
Broken tax vs Tax 18%
The left column is the type error everybody ends up searching for. The right one gives you a number you can sort, filter and chart like any other.
Dates from related pages follow the same pattern. Do not hand dateAdd the rollup. Pull a single date out of the list first, then work on that.
prop("Lines").map(current.prop("Due")).sort().last()
Latest due date from related lines
Once you have that date as a real date, everything from the due date labels article works on it exactly as written.
Conclusion
Now you know that a rollup which looks like a number can still be a list! Try Calculate β Sum first, since it is one click and it solves most of these. If you need a single value out of Show original, unwrap it with .first() or .at(0). And if you are writing a formula anyway, skip the rollup and map the relation directly.
When the error message mentions array or type number, stop adding toNumber() around the whole column. It cannot help you there. Unwrap first, then convert. π₯
I hope this article was helpful and easy to understand. At Prototion, we are on mission to make Notion easy for everyone! So we regularly post Helpful articles about Notion like this one. π
Remember to check out the Fantastic Formulas series for more articles about Notion formulas. Doesnβt matter if you are a Notion beginner or a pro, I believe you will find this series helpful. Also, donβt forget to follow us on π¦ Twitter for daily updates, latest Notion template launches and amazing deals & discounts on Premium Notion templates! π
Templates that do this for you
Built by independent makers on Prototion.
FreeList of languages
@LumibernThis is a simple list of 184 languages with the corresponding language codes according to ISO 639-1.
$20Birthday Plannings
@lunasa.businessBirthday Plannings gives you an ability to plan, manage and execute birthdays of your beloved ones all in one place.
$7To Do Dashboard
This To Do Dashboard takes a multiview approach to help you stay on top of your daily tasks.