cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Regular Visitor

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
Resolver I
Resolver I

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
Resolver I
Resolver I

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

Highlighted
Regular Visitor

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
Ignite

Microsoft Ignite

This will be a conference that you do not want to miss!

secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (3,393)