cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Super User
Super User

Sort collection by column in another collection?

Is this possible?

Scenario:

- Collection 1 (col1)

ID Name Characteristic Value
1 Bob Hair Blond
2 Sally Teeth White

- Collection 2 (col2)

ID Characteristic Order
1 Teeth 1
2 Hair 2

 

Is there a way to sort col1 by the "Order" column in col2 based on Characteristic?

Characteristic is the only column they have in common.

Thank you!

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Helper I
Helper I

Re: Sort collection by column in another collection?

Hi@

 

Add a new column in col1 using addcolumn function and lookup the order value into new column records,  then sort.

View solution in original post

Highlighted
Solution Sage
Solution Sage

Re: Sort collection by column in another collection?

Hi @ericonline 

To add to the suggestion made by @Jagadeeshk, you can try it this way:

Sort(
    AddColumns(colOne, "Order", LookUp(colTwo, _Characteristic = Characteristic, Order)), 
    Order, Ascending
)

 One suggestion though: either change the name of the Characteristic column in the collection to avoid confusion during the LookUp() or use the RenameColumns() function to do it. The screenshot below shows the output of the code above.

Regards,pa-forum-1.png


Fausto Capellan, Jr


Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

Proud to be a Flownaut!


View solution in original post

4 REPLIES 4
Highlighted
Helper I
Helper I

Re: Sort collection by column in another collection?

Hi@

 

Add a new column in col1 using addcolumn function and lookup the order value into new column records,  then sort.

View solution in original post

Highlighted
Solution Sage
Solution Sage

Re: Sort collection by column in another collection?

Hi @ericonline 

To add to the suggestion made by @Jagadeeshk, you can try it this way:

Sort(
    AddColumns(colOne, "Order", LookUp(colTwo, _Characteristic = Characteristic, Order)), 
    Order, Ascending
)

 One suggestion though: either change the name of the Characteristic column in the collection to avoid confusion during the LookUp() or use the RenameColumns() function to do it. The screenshot below shows the output of the code above.

Regards,pa-forum-1.png


Fausto Capellan, Jr


Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

Proud to be a Flownaut!


View solution in original post

Highlighted
Super User
Super User

Re: Sort collection by column in another collection?

You guys are the best. Thank you for your expertise. AddColumns always trips me up! I can never remember:
1.) Where to add it (during the ClearCollect or the Items property of the Gallery)

2.) The mental model of how it works. 

I added it to the Items property of the Gallery. Works great!

Take care

Highlighted
Solution Sage
Solution Sage

Re: Sort collection by column in another collection?

Hi @ericonline 

I did it directly in the Items property of the gallery as well. As for where to use the AddColumns(), it all depends on the scenario. I recently used it on a ClearCollect() to add an index column that needed to be generated on demand and then used for navigation purposes throughout the app.


Fausto Capellan, Jr


Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

Proud to be a Flownaut!


Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (11,265)