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.

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

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
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (81,504)