cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ajhstn
Helper I
Helper I

Sort by nested columns with custom ordering

Hi my collection is a Table with records and nested records.

 

Ie. MyTasks._links.priority.title, where _links and priority are also tables, and title is a record with values or either high, medium or low.

 

How do i sort by Status with a custom order ["high","medium","low"]

 

I have tried 

 

SortByColumns(MyTasks,"_links.priority.title",["high","medium","low"]) but this doesn't work.

1 ACCEPTED SOLUTION

Accepted Solutions
v-qiaqi-msft
Community Support
Community Support

Hi@ajhstn,

Based on the issue that you mentioned, do you want to sort a custom order in a nested table?

Could you please share a bit more about your collection?

In general, we sort using the following formula:

 

SortByColumns( Table, ColumnName, SortOrderTable )

 

You could not directly sort a nested table, you should add a column to store the "_links.priority.title" values and sort based on this added column.

I have a test on my side, please take a try as below.

I create a nested collection as below:

 

ClearCollect(
    MyTasks,
    {
        ID: 1,
        _links: {priority: {title: "high"}}
    },
    {
        ID: 2,
        _links: {priority: {title: "low"}}
    },
    {
        ID: 3,
        _links: {priority: {title: "medium"}}
    }
)

 

Add a Gallery to display this collection. To sort the custom order, set the Items property of the Gallery as below:

 

SortByColumns(
    AddColumns(
        MyTasks,
        "SortColumn",
        _links.priority.title
    ),
    "SortColumn",
    [
        "high",
        "medium",
        "low"
    ]
)

 

100903.png

Hope this could help you.

Best Regards,

Qi

View solution in original post

4 REPLIES 4
VijayTailor
Resident Rockstar
Resident Rockstar

Hi @ajhstn ,

You can use like below - 

SortByColumns(MyTasks,"_links.priority","Title",Ascending)

Thanks, 

v-qiaqi-msft
Community Support
Community Support

Hi@ajhstn,

Based on the issue that you mentioned, do you want to sort a custom order in a nested table?

Could you please share a bit more about your collection?

In general, we sort using the following formula:

 

SortByColumns( Table, ColumnName, SortOrderTable )

 

You could not directly sort a nested table, you should add a column to store the "_links.priority.title" values and sort based on this added column.

I have a test on my side, please take a try as below.

I create a nested collection as below:

 

ClearCollect(
    MyTasks,
    {
        ID: 1,
        _links: {priority: {title: "high"}}
    },
    {
        ID: 2,
        _links: {priority: {title: "low"}}
    },
    {
        ID: 3,
        _links: {priority: {title: "medium"}}
    }
)

 

Add a Gallery to display this collection. To sort the custom order, set the Items property of the Gallery as below:

 

SortByColumns(
    AddColumns(
        MyTasks,
        "SortColumn",
        _links.priority.title
    ),
    "SortColumn",
    [
        "high",
        "medium",
        "low"
    ]
)

 

100903.png

Hope this could help you.

Best Regards,

Qi

View solution in original post

Hi @VijayTailor that unfortunately doesn't work, it says "_links.priority" doesn't exist, but it actually does.  

 

Screen Shot 2020-10-09 at 20.40.06.png

 

Hi @v-qiaqi-msft amazing, that did it and i learned something new!  thank you

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

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

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 (43,669)