cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
simkessy
Helper I
Helper I

Get Count of values used in Multi Lookup

I have a multi lookup field in my sharepoint. 

 

I would like to get the disctinct count of each value used in that field. 

 

For example if I have 2 records:

 

 1. Janet, Steve, Corey

2. Janet, Mike, Corey

 

I need a collection with these values:

 

Name, Count

Janet, 2

Steve, 1

Corey, 2

Mike, 1

 

Is it possible for my PowerApp to generate this collection on load? 

 

1 ACCEPTED SOLUTION

Accepted Solutions
yashag2255
Dual Super User II
Dual Super User II

Hi @simkessy 

 

To create a collection for your requirement, use the expression:
 
Clear(CountCollection);ForAll(MultiLookupList,ForAll(Persons,If(!(DisplayName in CountCollection.Name),Collect(CountCollection,{Name: DisplayName,Count:1}),Patch(CountCollection,LookUp(CountCollection,Name = DisplayName),{Count:LookUp(CountCollection,Name = DisplayName).Count + 1}))))
 
You can add this expression on "OnVisible" property of your screen. Here, I have created a collection(CountCollection) with two columns(Name, and Count) to store the distinct values. MultiLookupList is the name of My SharePoint list with a column Persons(they have an attribute Display Name to get the person's name) that has the multiple selected persons. So we are applying two loops to iterate over each person selected in every record.  There is an if condition to check if current person already exist in the list. If it exists, it updates the count or else, creates a new record.MicrosoftTeams-image (99).png

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!

View solution in original post

2 REPLIES 2
yashag2255
Dual Super User II
Dual Super User II

Hi @simkessy 

 

To create a collection for your requirement, use the expression:
 
Clear(CountCollection);ForAll(MultiLookupList,ForAll(Persons,If(!(DisplayName in CountCollection.Name),Collect(CountCollection,{Name: DisplayName,Count:1}),Patch(CountCollection,LookUp(CountCollection,Name = DisplayName),{Count:LookUp(CountCollection,Name = DisplayName).Count + 1}))))
 
You can add this expression on "OnVisible" property of your screen. Here, I have created a collection(CountCollection) with two columns(Name, and Count) to store the distinct values. MultiLookupList is the name of My SharePoint list with a column Persons(they have an attribute Display Name to get the person's name) that has the multiple selected persons. So we are applying two loops to iterate over each person selected in every record.  There is an if condition to check if current person already exist in the list. If it exists, it updates the count or else, creates a new record.MicrosoftTeams-image (99).png

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!

v-yuxima-msft
Community Support
Community Support

Hi @simkessy 

 

Could you please reference @yashag2255 's suggestion?

If it works fine,please accept it as solution.

 

Best Regards.

Yumia

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,307)