web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Create a Collection Fo...
Power Apps
Answered

Create a Collection For All Branches

(0) ShareShare
ReportReport
Posted on by

Dear PoweRappers,

I have a bit too complex requirement (for me) as briefed below, looking for an easy solution please:

 

I have a SharePoint Branch List, containing records of all Branches information for many companies, including a column of ‘codes’ (Text field), and I would want to create a Collection in Power Apps, to extract the codes from all these branches where, the requested Company is equal to the Company in Branch List.

After we get a list of all the ‘codes’ in a collection, which may include duplicate/triplicates ‘codes’, I also want to filter-out unique codes, as a next step to get a list of unique ‘codes’ for each company.

 

The following function works for a single branch as copied below, I need For All branches:

ClearCollect(colAllCodes,Filter(colISICKSA, 'ACTIVITY CODE' in LookUp('Branches List', 'Branch CR No.'= galRequested.Selected.'CR Number', Activities).Value))

Codes

Laik_0-1694684902897.png

 

Where colAllCodes is new collection name

coISICKSA is a collection of all Codes (Master Codes List)

ACTIVITY CODE is the column field in colISICKSA

Activities is a Lookup field of Codes (looking up to Codes (Master Codes List)

 

Hope I am clear in expressing my request!

 

Thanks for the prompt response.

Categories:
  • MarkRahn Profile Picture
    1,424 Super User 2026 Season 2 on at

    Hi @Laik 

     

    The LookUp function only returns the first record found.

     

    https://learn.microsoft.com/en-us/power-platform/power-fx/reference/function-filter-lookup 

    LookUp returns only the first record found, after applying a formula to reduce the record to a single value. If no records are found, Filter and Search return an empty table, and LookUp returns blank.

     

    You need to use Filter or Search and then use Distinct to get the Distinct values.

    https://www.matthewdevaney.com/powerapps-collections-cookbook/unique-values-from-a-collection/ 

     

    I'm going to make some assumptions such as:

    1) only one Company is selected

    2) a single Company has multiple rows from the Branches List

    3) Activities is a single select Lookup field in the Branches List that is linked to the Master Codes List

     

    When a Company is selected from galRequested, in the OnSelect you should put something like:

     

    ClearCollect(
     colAllCodes,
     Distinct(
     Filter(
     'Branches List',
     'Branch CR No.' = galRequested.Selected.'CR Number'
     ),
     Activities.Value
     )
    );

     

    Filter will get all the matches for the Branch CR No. Distinct will get all the distinct Activities from the returned records.

     

    I don't think you need to reference colSICKSA which has a list of all your codes since Activities is a lookup on the Master Codes List which colSICKSA is built from.

     

    -Mark

    If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.

  • Laik Profile Picture
    on at

    Thanks Mark .. it seems to have worked ... can you let me know as to, how do I display these extracted Activities Codes in Gallery, screenshot is here 

    Laik_0-1694696383705.png

     

  • MarkRahn Profile Picture
    1,424 Super User 2026 Season 2 on at

    Hi @Laik 

     

    Is the Gallery you are asking about the galRequested one or a separate Gallery just to display the distinct Codes/Activities?

     

    For a separate Gallery, you would set the Data Source to colAllCodes and link to ThisItem.Value.

     

    -Mark

    If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.

  • Laik Profile Picture
    on at

    Dear Mark, 

    Thanks for your prompt response. 

    I have set the datasource/Gallery Items as colAllCodes and I was trying to show the unique codes in colAllCodes, in a Gallery, however I am getting this error.

    Laik_0-1694697614364.png

    Any thoughts?

     

     

  • MarkRahn Profile Picture
    1,424 Super User 2026 Season 2 on at

    Hi @Laik 

     

    ThisItem.Value should be used in the Gallery controls. I can't see from your screen shot what Property you have selected. I am going to guess it is the Items Property for the Gallery.

     

    Items for the Gallery should be colAllCodes. That is your Data Source. "Items" and "Data Source" are the same for a Gallery.

     

    When you drop controls in the Template of the Gallery such as a Title Label, you should set the "Text" Property to ThisItem.Value.  ThisItem references a record from your Collection colAllCodes.

     

    -Mark

    If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.

  • Laik Profile Picture
    on at

    Hey Mark, 

    Thanks for all your time and instant replies that is helping me a lot. As you can see, I have done exactly what you had asked me to do.

    After we create that collection colAllCodes,

    I have 3 branches for this company, 1 branch activity is blank, 2nd branch has 10 activities and the 3rd branch has 4 activities, the requirement is to have a total of 14 records minus the duplicates (4 activities in this case) ... the final outcome should list 10 unique activity codes in the column Value in 10 rows in colAllCodes.

    Laik_0-1694698575059.png

    Laik_1-1694698729043.png

    Laik_2-1694698905661.png

     

     

  • MarkRahn Profile Picture
    1,424 Super User 2026 Season 2 on at

    Hi @Laik ,

     

    What does your Branches List look like? What are the fields? The "Activities" field is a Lookup to your Master Codes List. Is the "Activities" field set to allow multi-select? It is unclear how your data is structured.

     

    -Mark

  • Laik Profile Picture
    on at

    Yes Mark, The Activities lookup field is multi-select field in the Branches List..

     

  • Verified answer
    MarkRahn Profile Picture
    1,424 Super User 2026 Season 2 on at

    Hi @Laik ,

     

    Someone else on here might know a better way but I think you need to use a temporary Collection to get all the values from the Activities multiselect Lookup field. Then get Distinct values from that Collection.

     

    Something like:

    Clear(colAllCodesWDuplicates);
    ForAll(
     Filter(
     'Branches List',
     'Branch CR No.' = galRequested.Selected.'CR Number'
     ),
     ForAll(
     ThisRecord.Activities,
     Collect(
     colAllCodesWDuplicates,
     ThisRecord.Value
     );
     );
     
    );
    ClearCollect(
     colAllCodes,
     Distinct(
     colAllCodesWDuplicates,
     Value
     )
    );

     

    The first ForAll will look thru the Items found from the Filter. The second ForAll will loop thru the values for the Activities/Codes. These values are added to a Collection. Then you can use Distinct to get those values.

     

    -Mark

    If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.

  • Laik Profile Picture
    on at

    Thanks Mark ... That was excellent ... it worked exactly the way I wanted. you are a gem.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 409 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 252 Most Valuable Professional

Last 30 days Overall leaderboard