When working with a data set, you may be looking to pull out a specific subset of your data — like the first item of a list, or the last 5 rows of a table. To allow you to extract the subset of the data that you need, Coda offers the First( ), Last( ), Nth( ), and Slice( ) formulas.
Our example uses a simple list of numbers: [1, 3, 5, 7, 11, 13]. These formulas allow specific items from the list to be filtered based on their position.
How to use formulas
First( ): Returns the first item from a list or table.
=List(1,3,5,7,11,13).First()
Output: 1
Last( ): Returns the last item from a list or table.
=List(1,3,5,7,11,13).Last()
Output: 13
Nth( ): Returns the Nth item from a list from the number provided.
=List(1,3,5,7,11,13).Nth(5)
Output: 11
Slice( ): Returns the part of the provided text or list based on the numerical position.
=List(1,3,5,7,11,13).Slice(2,4)
Output: [3, 5, 7]
Table of Definitions
Ways to use Slice
With Slice( ) in particular, there are a few different varieties you can try:
Give me the first 3:
=List(1,3,5,7,11,13).Slice(1,3)
1,3,5
Or, give me the last 2:
=List(1,3,5,7,11,13).Slice(-2)
11,13
And even, pull out specific rows:
I'm working with the Urgent Open Tasks table in our Product Launch Hub, and I wanted to get the last 3 rows of this table which are sorted by their End Date:
Using Slice, I'm able to build it into the core project table:
=[Urgent Open Tasks !!].Sort(True, End).Slice(-3)
Coda Tips!