cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ericonline
Community Champion
Community Champion

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
Jagadeeshk
Responsive Resident
Responsive Resident

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

faustocapellanj
Memorable Member
Memorable Member

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!

View solution in original post

4 REPLIES 4
Jagadeeshk
Responsive Resident
Responsive Resident

Hi@

 

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

faustocapellanj
Memorable Member
Memorable Member

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!

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

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!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

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