cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
chrisog
Level 8

Collect specified number of rows

Hi,

 

I was wondering if there is a way to collect a number of rows at once, with the number determined by a pre-existing value or user input.

 

For example, the user can input the number 4 into a text input and press a button, and a collection creates 4 rows from that.

 

Alternatively, a data source has an item with a value of n in a specified column. When a button is pressed, i want to create n rows in my collection.

 

Any ideas?

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Collect specified number of rows

@chrisog 

 

In case you just want to app rows based on the quantity in your data source, you can use the expression:
 
Clear(LocalCollectionName);
ForAll(FirstN([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],First(DataSource).Quantity),Collect(LocalCollectionName,{}))
This will create an empty collection with the number of rows equal to Quantity. I am assuming that your data source has just one row.
 
If you dont want to create a blank collection, you can add a SNo column or another column to your collection, which will make it easier to append data later.
 
Clear(LocalCollectionName);
ForAll(FirstN([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],First(DataSource).Quantity),Collect(LocalCollectionName,{SNo:Value}))
This support upto 20 rows, if you want to add more than that, please add the values in number array. 
 
Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
3 REPLIES 3
Super User
Super User

Re: Collect specified number of rows

Hi @chrisog 

 

If you are looking for something that create n number of rows from a data source into a collection, then you can use the expression:
 
ClearCollect(MyCollection,FirstN(Filter(DataSourceName, Status = "Test"),4))
 
This will collect first 4 rows, in case you want to set a variable for this, you can use Set(RowCount,4) and modify your expression as:
ClearCollect(MyCollection,FirstN(Filter(DataSourceName, Status = "Test"),RowCount))
Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
chrisog
Level 8

Re: Collect specified number of rows

Hi @yashag2255,

 

Thanks for the speedy reply. Unfortunately this is not what I want as the data source would, for example, have 1 row with the number value i want to collect in it.

 

I have a quantity column in my data source that would have a numeric value in it. I want my local collection to create a number of rows equal to the numeric value in the quantity column of that row in my data source. The data source itself would only encompass 1 row.

Super User
Super User

Re: Collect specified number of rows

@chrisog 

 

In case you just want to app rows based on the quantity in your data source, you can use the expression:
 
Clear(LocalCollectionName);
ForAll(FirstN([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],First(DataSource).Quantity),Collect(LocalCollectionName,{}))
This will create an empty collection with the number of rows equal to Quantity. I am assuming that your data source has just one row.
 
If you dont want to create a blank collection, you can add a SNo column or another column to your collection, which will make it easier to append data later.
 
Clear(LocalCollectionName);
ForAll(FirstN([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],First(DataSource).Quantity),Collect(LocalCollectionName,{SNo:Value}))
This support upto 20 rows, if you want to add more than that, please add the values in number array. 
 
Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

PowerApps Monthly Community Call

Next Wednesday, September 18th at 8am PDT

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Users Online
Currently online: 171 members 4,688 guests
Please welcome our newest community members: