I have a rollup property called “Task Rollup” that contains multiple numeric values. These values come from a formula field in my Task database since I can’t create a rollup from another rollup.
I want to create a formula that calculates the mean of all these numbers in the rollup property.
The main problem is that rollup columns have calculation options like Sum and Average at the bottom, but rollup properties with arrays of values don’t have these calculation features available.
I know I need to find both the total and count of numbers in the array, but I’m having trouble figuring this out.
I tried using .toNumber() but it only gives me the first number from the array. The .format() method doesn’t help either and I still get the count instead of what I need.
Any help would be great, thanks!
Notion rollup arrays can be challenging at times. A reliable approach I’ve found is to use map() to convert the numbers in the rollup to numeric values and then sum them up. Ensure to check if the rollup array is not empty to avoid division errors. You can use this formula: prop("Task Rollup").map(current => current.toNumber()).sum() / prop("Task Rollup").length(). The key is to process each number accurately while being aware of the array’s state.
Yeah, this is a super common issue with Notion rollup arrays. I’ve dealt with this before - you need to treat the rollup as an array and use reduce to calculate manually. Try prop("Task Rollup").reduce((acc, cur) => acc + cur.toNumber(), 0) for the sum, then divide by prop("Task Rollup").length(). Your full formula: prop("Task Rollup").reduce((acc, cur) => acc + cur.toNumber(), 0) / prop("Task Rollup").length(). Works way better than map and handles edge cases. Just watch out for null values - they’ll break it.
i understand ur struggle! you could try using map() with toNumber() on the rollup prop. then do sum() on that and divide it by length() like this: prop("Task Rollup").map(cur => cur.toNumber()).sum() / prop("Task Rollup").length(). it should give u the mean!