web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Sort list of number to...
Power Apps
Unanswered

Sort list of number to create hierarchy in gallery.

(0) ShareShare
ReportReport
Posted on by 124

I have a list of numbers.

[

1,

2,

3,

1.1,

1.2,

1.3,

1.11,

1.12,

2.1,

2.12,

2.2,

2.3,

3.1,

3.11,

3.2

]

I want to sort this list in such a way that it becomes like this.

[

1,

1.1,

1.2,

1.3,

1.11,

1.12,

2,

2.1,

2.2,

2.3,

2.12,

3,

3.1,

3.2,

3.11

]

 

How can I achieve this?

Categories:
I have the same question (0)
  • Verified answer
    AJ_Z Profile Picture
    3,711 Super User 2024 Season 1 on at

    this is possible but many people do it different ways I do this using AddColumns(),Split(),SortByColumns() and If().
    for my example i will call my datasource 'ABC' and my decimal number column 'numb'
    So i go to my gallery and add in this

    SortByColumns(
     AddColumns(
     ABC,
     "BefD",
     Value(
     First(
     Split(
     ThisRecord.numb,
     "."
     )
     ).Result
     ),
     "AftD",
     If(
     CountRows(
     Split(
     ThisRecord.numb,
     "."
     )
     ) = 1,
     0,
     Value(
     Last(
     Split(
     ThisRecord.numb,
     "."
     )
     ).Result
     )
     )
     ),
     "BefD",
     Ascending,
     "AftD",
     Ascending
    )


    You will need to change ABC to the name of your datasource. You will need to change anywhere you see numb to your decimal column. 

    i have tested it out in an app i built for this see the below picture of what your gallery should sort like:

    AJ_Z_0-1641383783511.png

     

  • AJ_Z Profile Picture
    3,711 Super User 2024 Season 1 on at

    Let me know if my above suggestion works for you 🙂

  • Usman2 Profile Picture
    124 on at

    @AJ_Z 
    Amazing solution, but what is the number of "." in the value is not just one but N number of ".". Than how should we handle this?

  • AJ_Z Profile Picture
    3,711 Super User 2024 Season 1 on at

    I am slightly confused by the question apologies if I am not understanding are you saying that the there might be more than one decimal point (if so how many decimal points) or are you asking something else 🙂

  • AJ_Z Profile Picture
    3,711 Super User 2024 Season 1 on at

    I re-read the question and believe I understand what  you are asking better this is an example of what I would do to accommodate up to 4 "." e.g.  1.2.3.4.5

    for my example i will call my datasource 'ABC' and my decimal number column 'numb'
    So i go to my gallery and add in this

    SortByColumns(
     AddColumns(
     ABC,
     "BefD",
     Value(
     First(
     Split(
     ThisRecord.numb & ".0.0.0.0.0",
     "."
     )
     ).Result
     ),
     "Aft1D",
     Value(
     Last(
     FirstN(
     Split(
     ThisRecord.numb & ".0.0.0.0.0",
     "."
     ),
     2
     )
     ).Result
     ),
     "Aft2D",
     Value(
     Last(
     FirstN(
     Split(
     ThisRecord.numb & ".0.0.0.0.0",
     "."
     ),
     3
     )
     ).Result
     ),
     "Aft3D",
     Value(
     Last(
     FirstN(
     Split(
     ThisRecord.numb & ".0.0.0.0.0",
     "."
     ),
     4
     )
     ).Result
     ),
     "Aft4D",
     Value(
     Last(
     FirstN(
     Split(
     ThisRecord.numb & ".0.0.0.0.0",
     "."
     ),
     4
     )
     ).Result
     )
     ),
     "BefD",
     Ascending,
     "Aft1D",
     Ascending,
     "Aft2D",
     Ascending,
     "Aft3D",
     Ascending,
     "Aft4D",
     Ascending
    )

    You will need to change ABC to the name of your datasource. You will need to change anywhere you see numb to your decimal column. 

    i have tested it out in an app i built for this see the below picture of what your gallery should sort like:

     

    AJ_Z_0-1641550962826.png

     

     

  • zerocool55 Profile Picture
    94 on at

    Hi AJ,

     

    I have tried your instruction but I have an error: Value has some invalid arguments.

     

    Any pointers?

     

    SortByColumns(
        AddColumns(
            ProjectTasks,
            "BefD",
            Value(
                First(
                    Split(
                        ThisRecord.TaskLevel,
                        "."
                    )
                ).Result
            ),
            "AftD",
            If(
                CountRows(
                    Split(
                        ThisRecord.TaskLevel,
                        "."
                    )
                ) = 1,
                0,
                Value(
                    Last(
                        Split(
                            ThisRecord.TaskLevel,
                            "."
                        )
                    ).Result
                )
            )
        ),
        "BefD",
        SortOrder.Ascending,
        "AftD",
        SortOrder.Ascending
    )

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard