Using Slice to limit the rows in a view (return Top n rows)

Want the first N rows that match a query? Use Slice in your filter:

First 5 tasks with highest priority: thisRow.in([Todo List].Sort(false,Priority).Slice(0,5))

21 Likes

Great tip! This is especially awesome when using BulletedList() on the canvas so that you can show a summary in list format.

3 Likes

Iā€™m not having the same luck. Based on the above I would expect that just adding Table.Slice(0,3) to the table filter would just give me the top 3 rows of the table. When I do that, thatā€™s not what Iā€™m seeing. Iā€™m actually seeing that it doesnā€™t do anything.

Iā€™m having problems getting this to work as well. Do you put this in the main filter for the table? It doesnā€™t seem to have any effect at all.

Thanks!
ā€“ Maria

Hereā€™s an example with a walkthrough of the key steps:

25 Likes

Thanks so much! That totally helped.
Makes it easy to sort and filter a row, then just pull out the first X rows of it. Nice!

Thanks,
Maria

@shishir Hey this works great but the performance tool indicates its expensive. Any other way to do it without slowing down?

Hi @Johg_Ananda, Mind sharing what you are seeing in the performance tool and the exact formula? Thanks!

I donā€™t know an easy way to demonstrate this, to get the performance load issue you need a big doc and there isnā€™t an easy way to randomize or share mine. I am getting this impression because when I used this approach I saw in the performance tool the table filter show up as a resource drain. It was remarkable because Iā€™ve never seen a view filter show up, let alone significantly.

Itā€™s gone but next time I see it Iā€™ll take a gif or something @Jason_Tamulonis.

1 Like

Hello. It works for me but thereā€™s something extra I wanted to do.
I have a task table with some columns, but the ones that matter for this are Urgency(returns a float falue) and Status(Returns a pre-defined string such as ā€˜to-do, waiting, done, cancelledā€¦ā€™).
Very well, I want to apply the slice in Urgency and sort it out by the highest value. Hereā€™s the fĆ³rmula:

thisRow.In(thisTable.Sort(false(),thisTable.Urgency).Slice(1,3))

It works fine, but it brings all the tasks with all Statuses and I want to exclude some status from the result. However, if I try a different filter, itā€™ll apply over the previous one that is sliced already. For instance, letā€™s say that I have 5 tasks:

Task - Status - Urgency
Task 5 (Next)(12)
Task 7 (Cancelled)(13)
Task 13 (To do)(15)
Task 2 (Waiting)(20)
Task 3 (To do) 17

The formula would return the tasks in this order: Task 2, Task 3 and Task 13, and thatā€™s fine. But if I add another filter (letā€™s say that I want to filter out the status Waiting), then the two combined would return only Task 3 and Task 13. Thatā€™s kind of obvious, but what I want to do is filter statuses out and still receiving 3 values in a way that it would return the tasks 3, 13 and 7.

One way to do it (but that I cannot figure out how to apply a formula like this) would be having a formula that:

  1. Sorts Urgency from highest number to low;
  2. Filters out some statuses that I do not with to be shown;
  3. Slice the result of the sort and the filter

Looks easy, but how to implement this in Coda?

Thanks in advance

@Dan_Rose @shishir thank you very much for those ideas, iā€™ve had the problem of limiting results from filter for at least the past year, game changer! :heart_eyes_cat:

@Tiago_Melo iā€™ve figured out that the best way (in terms of practicality and not speed or performance) is to filter using an intermediate table, what i mean is that you filter and sort the original table, then you just use the Danyliuk Method (thanks to the legendary @Paul_Danyliuk) and in a new column in a new table you write [yourtable], this will create a link to your existing, sorted & filtered table, then you simply add ā€œ.slice(x,y)ā€ to that formula and youā€™re done!

P.s. thatā€™s actually what iā€™ve just done, it works flawlessy :blush:
Let me know if that help! :upside_down_face:

1 Like

I have been trying to achieve something similar (I want my next 5 tasks) but I want to filter out those that are complete and if I adapt @Dan_Roseā€™s formula

thisRow.in([Todo List].Sort(false,Priority).Slice(0,5))

to sort by the Complete column it just wonā€™t do it. It wonā€™t just do the sort if I remove the Slice() either. Any ideas?

1 Like

@Mary-Ann_Horley this would be easier to help if you had a working doc, but right now it looks like the Sort() is working on the In() whereas you may want the sort to run after the filtering / In().

1 Like

I have mocked up a dummy table and view which is embedded below:

Thanks for your help!

1 Like

Apologies, as I know this is quite an old thread (Iā€™m new here, wasnā€™t entirely sure where to post.) I used this exact formula, but can not get it to work on any table in any of my docs? This is what I put in the filter formula section:

Slice(thisTable,1,10)

and the output is still 80 of 80 rows? What Iā€™m actually trying to do is pull the last ten rows, but as I canā€™t seem to get this working, Iā€™m a bit confused. If anyone can point out my error, that would be great!

1 Like

hi @Mckenna_Coffey

what about thisTable.ColumnName.Slice(1,10)

should give a different result, cheers, Christiaan

1 Like

Thanks for the prompt suggestion. Helpful, but still nothing. Says 80 of 80 rows match the filter.

maybe you can consider to share a doc with the issue, so we can have a look

in this post you see how slice can work : Referencing the cell above - #28 by Christiaan_Huizer

1 Like

Hi, guys.

Iā€™ve used the formula [thisRow.In(thisTable.Sort(false, thisTable.crITic).Slice(1, 5))] to view the last X rows, but it seems that it doesnā€™t ā€œcollaborateā€ with another added filter, despite their order.

This is how it looks just with the split filter:

image

and this is how it looks when I filter by daily/zilnic column.

image

image

Iā€™ve also tested it with a checkbox column and the result is the same as in my case (lookup column).

Do you have any idea? Thanks.

1 Like

Hello @Alexandru_Dan ,
I donā€™t mind helping you out and I do have a gut feeling about the cause of your problem, but if you donā€™t show us the daily/Zilnic column, it is kind of hard to give you any advise.
If you share a dummy doc with your setup, but without any private data, you will get the best help, and usually pretty quick too.
Greetings, Joost

1 Like