cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
deveDennis
Level: Powered On

Sorting gallery based on a calculated value

Hello all,

I am in need of your help.

I am trying to sort a gallery based on a score that is calculated for each item in the gallery.

It's like a matching process where in List1 i have Title and a lookup column from List2 containing multiple values, also i have a combobox populated with List2's items. So you select wich items from List2  you want to filter the gallery (List1) on and then i have a label in the gallery calculating "Combobox's NumberOfPickedItems / NumberOfMatchedItems in List1's Lookup column. So i want to sort the gallery based on that value.

 

Since it's not a column in the list it's harder to sort it.

I also tried to create a collection with a column containing the calculated value but since the lookup column is a table-value it won't do t for me.

Do you have any ideas?

 

Much appriciated,

deveDennis

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
JimmyBecks
Level: Powered On

Re: Sorting gallery based on a calculated value

Hi deveDennis,

 

I recreated the two lists you described in your post (very simply) to work as shown below:


LookupDemo1.png

 

In PowerApps I have added ComboBox control and a Gallery. The ComboBox is set to display the Title column of List2. This ComboBox is set to allow multiple selections and to the OnChange property I have added the following formula:

 

 

ClearCollect(
    GalleryItems,
    AddColumns(
        List1,
        "NumberOfMatches",
        CountRows(
            Filter(
                LookUpColumn,
                Value in ComboBox1.SelectedItems.Title
            )
        )
    )
)

 

This creates a new collection that contains List1 along with a new column that is the count of how many values in each of List1's lookup column appear in the values selected in the ComboBox.

 

I have then set the items property of the Gallery to be the new GalleryItems collection sorted by the "NumberOfMatches" columns with the following formula:

 

SortByColumns(GalleryItems,"NumberOfMatches",Descending)

This results in the 10 rows of List1 being sorted by the number of matches they have in the selected items.LookupDemo2.png

 

With this value calculated you can probably do some funky maths to work out the percentage match etc.

 

Hope this helps, it was fun to figure out Robot Happy

 

 

2 REPLIES 2
Highlighted
JimmyBecks
Level: Powered On

Re: Sorting gallery based on a calculated value

Hi deveDennis,

 

I recreated the two lists you described in your post (very simply) to work as shown below:


LookupDemo1.png

 

In PowerApps I have added ComboBox control and a Gallery. The ComboBox is set to display the Title column of List2. This ComboBox is set to allow multiple selections and to the OnChange property I have added the following formula:

 

 

ClearCollect(
    GalleryItems,
    AddColumns(
        List1,
        "NumberOfMatches",
        CountRows(
            Filter(
                LookUpColumn,
                Value in ComboBox1.SelectedItems.Title
            )
        )
    )
)

 

This creates a new collection that contains List1 along with a new column that is the count of how many values in each of List1's lookup column appear in the values selected in the ComboBox.

 

I have then set the items property of the Gallery to be the new GalleryItems collection sorted by the "NumberOfMatches" columns with the following formula:

 

SortByColumns(GalleryItems,"NumberOfMatches",Descending)

This results in the 10 rows of List1 being sorted by the number of matches they have in the selected items.LookupDemo2.png

 

With this value calculated you can probably do some funky maths to work out the percentage match etc.

 

Hope this helps, it was fun to figure out Robot Happy

 

 

deveDennis
Level: Powered On

Re: Sorting gallery based on a calculated value

Hey JimmyBecks,

 

This is exactly what I needed, works perfectly!

Nice job and thanks alot! Smiley Happy

/Dennis

Helpful resources

Announcements
firstImage

PowerApps Monthly Community Call!

Join us next Wednesday for our Demo Extravaganza, October 16, 2019 8am PDT.

firstImage

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Top Community Contributors for September  2019

Top Community Contributors for September 2019 🎉🎉

Let's thank our top community contributors

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

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

Top Kudoed Authors
Users Online
Currently online: 430 members 5,290 guests
Please welcome our newest community members: