cancel
Showing results for 
Search instead for 
Did you mean: 

How to filter n rows in a collection

ChandaSuman
Level 2
I have a collection which is a final collection after using sort collection. From that final collection, I want to filter only "n' rows for example only Top 3 from that collection. 

So my final output collection should look like
1. Suman3 - 52.3
2. Suman4 - 42.2
3. Suman - 40.99

Could someone please help me on this?
16267.png


------------------------------
Chanda Suman
Sr. Automation Specialist II
S&P Global
Asia/Kolkata
------------------------------
5 REPLIES 5

Yeswa_Vaibhav_1
Level 6
Hi Suman,

I just need to know on what criteria you are going to filter for 'n' rows from final collection which is sorted? or
just need only 'n' rows from top of collection without any filter specification?

Regards,

------------------------------
Yeswa Vaibhav Alwar Nerella
Associate Consultant
Capgemini
Asia/Kolkata
------------------------------

Hi Vaibhav,

Thanks for the reply. I won't have any filter specifications. 

In your words. I require "just need only 'n' rows from top of collection without any filter specification?"

------------------------------
Chanda Suman
Sr. Automation Specialist II
S&P Global
Asia/Kolkata
------------------------------

In  that case you can copy those number of rows to another collection, by using copy rows action stage in Collection Manipulation VBO. Add as many rows you need. Refer screenshot.

16260.png

Let me know if it is not clear. It will work.

Regards,

------------------------------
Yeswa Vaibhav Alwar Nerella
Associate Consultant
Capgemini
Asia/Kolkata
------------------------------

Thanks Vaibhav... This definitely helps and will use this one for sure.

Anything we could do using "Filter Collection" under Utility collection manipulation?

------------------------------
Chanda Suman
Sr. Automation Specialist II
S&P Global
Asia/Kolkata
------------------------------

The code stage within "Filter Collection" currently only uses the DataTable.Select() method, which does not support this. However, you could make a clone of this action and supply an input for number of rows you need. This will also require some changes to the object dependencies, which I'll list below.

In code options, add to External References:
System.Data.DataSetExtensions.dll
System.Core.dll

In code options, add to External References:
System.Linq (It boggles my mind that this isn't in here to begin with, but that's neither here nor there.)

Add input:
number - Number (Specifies number of top rows to pull)

Change line 3 to:
Add to ln 13:
Collection_Out = Collection_Out.AsEnumerable().Take(number).CopyToDataTable()

Edited to take top rows post-filter instead of pre-filter
------------------------------
Ami Barrett
Sr Product Consultant
Blue Prism
Plano, TX
------------------------------