Stumped by Slice()

Hi…I have used Slice() many times in the past, but I am stumped today.

I have a table with a price column and ABS() of price change.

I want to filter out prices less than $20, do a descending sort of ABS(), and use Slice to display the top 15 rows of data…but after filtering price and sorting ABS, I cannot get Slice to work:

thisRow.Price > 20 AND thisRow.in(thisTable.Sort(false,thisTable.ABS))

Can anyone help?

Many thanks!

Gregg

Share a doc!

You should really tag on slice at the very end though.

So first filter, then sort, then slice

Thank you for confirming the right order: Filter, Sort, Slice.
But I still can’t get Slice to work.
Here’s a sample document…my goal is to see only the first 15 entries.

Thank you for any help you can offer!

Hi, you can use :
for 15 first entries sort by price

View.Sort(False(), View.Price).Slice(0, 15).BulletedList()

1 Like

I’m still struggling with this. I can get the following to sort of work…except the sliced result is never 15, it’s always less than that, and I suspect it’s just giving me all entries with price over 20 that meet the other criteria. But shouldn’t it filter out everything with price below 20, then give me the first 15 after that?
thisRow.Price>20 AND thisRow.in(thisTable.Sort(false,thisTable.ABS).Slice(0,15))

yes. use filter in you table before sort.

Table.filter( price > 20).sort(false(), thisTable.ABS).slice(0,15)

View is table of object. Slice take 15 first item. If you need sort or filter use before slice.

1 Like

I’m sorry to be such a dope, but I cannot get this to work - the filter of price > 20 works, but the slice does not, you can see it outputs 51 rows instead of 15:
image

to return the first 15 items, use Slice(1,15)

start position is 1
end position is 15

Coda uses 1-based indexing for arrays (unlike js which uses 0-based indexing)

1 Like

When working on table filters it’s a little different, the help you’ve been getting is for formulas external to the table.

All you need to do now is adding .Contains(thisRow)

Like this:

thisTable.Filter(Price > 20).Sort(false, thisTable.ABS).Slice(1, 15).Contains(thisRow)
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.