Last active
August 6, 2024 00:22
-
-
Save typeoneerror/eb743867c7c6a1e08d0fe351be2e4fa0 to your computer and use it in GitHub Desktop.
Pseudo Notion rollup calculations as Formulas 2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lets( | |
values, prop("Values").map(current.prop("Value")).filter(!current.empty() || current == 0), | |
values.sum() / values.length() | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prop("Values").length() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prop("Values") | |
.map(current.prop("Value")) | |
.filter(!current.empty() || current == 0) | |
.length() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lets( | |
/* Sorted list of non-empty dates */ | |
dates, prop("Values").map(current.prop("Date")).filter(!current.empty()).sort(), | |
/* Create a date range with the first and last dates */ | |
range, dateRange(dates.first(), dates.last()), | |
/* How many periods between the dates */ | |
days, dateBetween(range.dateEnd(), range.dateStart(), "days"), | |
months, dateBetween(range.dateEnd(), range.dateStart(), "months"), | |
years, dateBetween(range.dateEnd(), range.dateStart(), "years"), | |
/* Some years and months have more/less days, but this is the simplest way to do this that is close enough to Notion's output */ | |
count, ifs( | |
years > 0, days / 365, | |
months > 0, days / 30, | |
days | |
), | |
/* Notion's rollup displays years, months or days based on how big the range is */ | |
period, ifs( | |
years > 0, "year", | |
months > 0, "month", | |
"day" | |
), | |
/* Round to nearest 10th */ | |
count, round(count * 10) / 10, | |
/* Add period to count and "s" if only 1 */ | |
count + " " + period + (count == 1 ? "" : "s") | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lets( | |
values, prop("Values").map(current.prop("Value")), | |
values.max() | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lets( | |
values, prop("Values").map(current.prop("Value")).filter(!current.empty() || current == 0).sort(), | |
mid, (values.length() / 2).floor(), | |
value, values.length() % 2 == 0 ? (values.at(mid) + values.at(mid - 1)) / 2 : values.at(mid), | |
value | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lets( | |
values, prop("Values").map(current.prop("Value")), | |
values.min() | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lets( | |
values, prop("Values").map(current.prop("Value")).filter(!current.empty() || current == 0).sort(), | |
ifs(values.length() > 1, values.last().toNumber() - values.first().toNumber(), 0) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prop("Values") | |
.map(current.prop("Value")) | |
.sum() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment