cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
seadude
Level 10

ClearCollect last 10 records from Data Source

Hello.

 

What am I missing here? I'm having trouble putting together the syntax to Collect the last 10 records from a data source.

The data source has a unique ID and data columns, but these aren't really queryable in this case. I was thinking something like:

ClearCollect(
    colLast10,
        Filter(dataSource,
            x -y))

But I can't figure out what "x" nor "y" could be. CountRows(dataSource) - 10? Nope, Last(dataSource) - 10? NOpe
... Any ideas?

Thank yoU!

2 ACCEPTED SOLUTIONS

Accepted Solutions
Super User
Super User

Re: ClearCollect last 10 records from Data Source

Hi @seadude,

ClearCollect(colLastten,LastN(datasource,10))

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-first-last

If this answers your question please mark it solved.

Super User
Super User

Re: ClearCollect last 10 records from Data Source

Just a tip but for data sources that exceed 2000 or may do so in the future as the items in the data source grow, Use FirstN(Sort(datasource, ID,Descending),10) to avoid delegation problems. This works even with huge datasources.
3 REPLIES 3
Super User
Super User

Re: ClearCollect last 10 records from Data Source

Hi @seadude,

ClearCollect(colLastten,LastN(datasource,10))

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-first-last

If this answers your question please mark it solved.

seadude
Level 10

Re: ClearCollect last 10 records from Data Source

Thank you for sharing. I almost spelled it out in the Post Title! AH!

Super User
Super User

Re: ClearCollect last 10 records from Data Source

Just a tip but for data sources that exceed 2000 or may do so in the future as the items in the data source grow, Use FirstN(Sort(datasource, ID,Descending),10) to avoid delegation problems. This works even with huge datasources.