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

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (12,348)