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

 

 

View solution in original post

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

 

 

View solution in original post

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! 🙂

/Dennis

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (4,707)