Skip to main content

First, Last, Nth, and Slice formulas

Mastering list management with Coda formulas: First(), Last(), Nth(), and Slice()

Updated this week

When working with a data set, it’s great to know you can easily grab just what you need, like the very first item in a list, or the last five rows of a table! Coda makes this super simple with handy formulas like First(), Last(), Nth(), and Slice(). In this article, you’ll learn how to use these formulas to manage all kinds of lists in Coda.

Within this article, you’ll find...


ℹ️ In this article, we’ll use a simple list of numbers for all of our examples:
[1, 3, 5, 7, 11, 13]

These formulas allow specific items from the list to be filtered based on their position. Please note that the first item in the list has index 1 in Coda formulas.

First()

The formula First() returns the first item from a list or table. It requires only one input: the list or table.

List(1,3,5,7,11,13).First()

Formula Output: 1

Last()

The formula Last() returns the last item from a list or table. It requires only one input: the list or table.

List(1,3,5,7,11,13).Last() 

Formula Output: 13

Nth()

The Nth() formula returns the item in the Nth position in a list, based on the number provided. It requires two inputs: the list or table, and the position.

In the example below, the formula is seeking the item that’s in the 5th position in the list.

List(1,3,5,7,11,13).Nth(5)Formula 

Output: 11

Slice()

The Slice() formula returns part of the provided text or list based on the numerical position. It requires two inputs: a text string or list, and a position to start counting from. There is another optional input: the position to stop counting

In the example below, the formula intends to pull the items in the list starting from position 2 and ending at position 4.

List(1,3,5,7,11,13).Slice(2,4)

Formula Output: 3, 5, 7

Other ways to use Slice()

With Slice() in particular, there are a few different varieties you can try:

Give me the first 3 in the list:

List(1,3,5,7,11,13).Slice(1,3)Formula Output: 1,3,5

Give me the last 2 in the list:

For this one, you can use a negative number to pull the items at the end of the list. This is especially useful if you don’t know how many total items are in the list and therefore aren’t sure what starting position to use.

List(1,3,5,7,11,13).Slice(-2)Formula Output: 11,13

Pull out specific rows from a table:

Let’s say you’re working with a tasks table, and you want to pull the last 3 rows of this table, which are sorted by their End Date:

1_1 - 2025-04-17T143130.799.png

Using Slice(), you’re able to surface those rows easily! Here’s an example of what that formula would look like:

[Tasks].Sort(True, End Date).Slice(-3)


Related resources

Did this answer your question?