When a formula returns an array of entities, it would be great to be able to sort them and “slice” the data to only show a portion of the data set.
Coda calls this the slice formula and defines it: The Slice() formula returns part of the provided text or list based on the numerical position. There is another optional input: the position to stop counting
Example Uses:
Compute the previous 4 meetings from the same meeting type (enum)
Reveal the last 5 payments per client on each client entity
Compute the 3 ticket types with the most tickets in the service desk in the monthly report entity.
Hi. Since First() and Last() exist, for a very contrived, bad, hacky attempt at this, I tried creating nested formulas that exclude the last/first from inner to outer layers, but unfortunately, I was unable to come up with a single-formula hack, since I got the error: Ouch, we can't calculate Count, Sum, Join, Avg, Min, Max, First or Last inside a Filter. Please create two Formulas instead.
So, only in very specific and urgent cases (more of a proof of concept that anything else), you can create n+1 columns to get the top/bottom-n by any sort, as shown in my example of getting the top 3 Tasks by Priority in a Projects table.
Formula Column: Task #1
Sorts all Tasks by Priority and takes the last one, which is the top-priority Task.
Tasks.Sort(Priority).Last()
Formula Column: Task #2
Sorts by Priority but excludes Task #1 by Public Id, then takes the last one, which is the 2nd-priority Task.
You can of course adapt these if you want to find the Nth item based on a different sort order than rank.
I think you can extend this to return a batch of items, by adjusting the ID to find formula so that it returns a string of Ids (with delimiters) and then use a Find()>0 function in the Nth bug formula