cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
comandante
Frequent Visitor

Create multiple collections

I have a gallery (the source is a SharePoint list) with a checkbox. I have a field User in every item of my gallery. For every User there can be multiple records in a gallery.
On the OnCheck property I collect all checked items into my SelectedItems collection.
After that, I use Collect(UniqueUser, Distinct (SelectedItems, User)) to create a collection of unique Users of my SelectedItems collection.

 

Question: how can I create a separate collection for every unique user? The nr of unique users is different every time and depends on the checkbox.
Thank you in advance for your help

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @comandante ,

Second (or last) one is easy

ClearCollect(
   UniqueCollection1,
   Filter(
      SelectedItems,
      User=Last(UniqueUser).Result
   )
);

You can however do any number - second one which is not last

ClearCollect(
   UniqueCollection1,
   Filter(
      SelectedItems,
      User=Last(FirstN(UniqueUser,2)).Result
   )
)

For the third, change the 2 to 3 and so on.
BTW SelectedItems is not a good name for a collection as it is a Reserved Word in Power Apps.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

View solution in original post

6 REPLIES 6
WarrenBelz
Super User
Super User

Hi @comandante ,

If I understand you correctly, you would do the same thing to the List, however it is not Delegable

ClearCollect(
   UniqueUsers, 
   Distinct(
      SPListName,
      User
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

Hi @WarrenBelz 

Thanks for your respond

This is not exactly what I'm looking for. Let me give you an example

For example: I have checked 2 items in gallery and now I have 2 records in my SelectedItems Collection. Every record has unique User

I tried to use this formula to get them in 2 different collections(this is all I need), but it didn't work

If((First(SelectedItems.User)).User=First(UniqueUser).Result, ClearCollect(UniqueCollection1, ThisItem), ClearCollect(UniqueCollection1, ThisItem));

 

If I use this formula  ClearCollect(UniqueCollection1,Filter(SelectedItems,User=First(UniqueUser).Result));

the first UniqueUser from a collections goes to a separate collection, but how can I get the second one? 

And what to do if I have 10 unique users? 

 Sorry if my questions sounds weird, I'm quite new to PowerApps

Thanks again for your help.

 

 

Thanks again! 

 

Hi @comandante ,

Second (or last) one is easy

ClearCollect(
   UniqueCollection1,
   Filter(
      SelectedItems,
      User=Last(UniqueUser).Result
   )
);

You can however do any number - second one which is not last

ClearCollect(
   UniqueCollection1,
   Filter(
      SelectedItems,
      User=Last(FirstN(UniqueUser,2)).Result
   )
)

For the third, change the 2 to 3 and so on.
BTW SelectedItems is not a good name for a collection as it is a Reserved Word in Power Apps.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

@WarrenBelz 

Thank you very much! This works good. 

Now I would like to set nr of collections to be created to a variable - Set(UniqColVar, CountA(molUnique)) and

my last question - is there a way I can loop this in ForAll?

 

 

Hi @comandante ,

Not really as you cannot dynamically name collections.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

Thank you @WarrenBelz 

It explains everything

Is anything you'd suggest in my case? 

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (1,628)