# Slice and Sort lookup fields

**URL:** <https://community.fibery.io/t/slice-and-sort-lookup-fields/9564>\
**Category:** Misc\
**Created:** [September 10, 2025, 3:43pm UTC](https://community.fibery.io/t/slice-and-sort-lookup-fields/9564 "2025-09-10T15:43:38Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Sev](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@Sev](https://community.fibery.io/u/Sev)\
**Post date:** [September 11, 2025, 12:03am UTC](https://community.fibery.io/t/slice-and-sort-lookup-fields/9564/2 "2025-09-11T00:03:37Z")

</div>

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**.

```auto
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**.

```auto
Tasks.Filter(
	[Public Id] != [This Project].[Task #1].[Public Id]
).Sort(Priority).Last()

```

#### Formula Column: Task #3

Sorts by Priority but excludes Task #1 and Task #2 by Public Id, then takes the last one, which is the **3rd-priority Task**.

```auto
Tasks.Filter(
	[Public Id] != [This Project].[Task #1].[Public Id] and
	[Public Id] != [This Project].[Task #2].[Public Id]
).Sort(Priority)
.Last()

```

#### Formula Column: Top-3 Tasks A-Z

Filters for the **top 3 Tasks** , using Task #1, #2 and #3 by Public Id and sorts by Priority. **See IMPORTANT NOTE below.**

```auto
Tasks.Filter(
	[Public Id] = [This Project].[Task #1].[Public Id] or
	[Public Id] = [This Project].[Task #2].[Public Id] or
	[Public Id] = [This Project].[Task #3].[Public Id]
).Sort(Priority)

```

The sorting is not respected by the collection output, but only for aggregations such as Join(), as discussed in my message quoted below.

> [@Sort and filter on the Lookup field](https://community.fibery.io/t/sort-and-filter-on-the-lookup-field/3788/5):
>
> ❌ The problem is that **the sort is not respected in the field’s UI**. But of course the formula itself does return it sorted, as we can confirm if we return the value as a joined text field by adding `.Join(Contact.Name, ",")`.

---

_[View the full topic](https://community.fibery.io/t/slice-and-sort-lookup-fields/9564)._
