web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details
Power Apps - Building Power Apps
Answered

Sort list of number to create hierarchy in gallery.

Like (0) ShareShare
ReportReport
Posted on 5 Jan 2022 10:56:14 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)
  • zerocool55 Profile Picture
    94 on 01 Jul 2023 at 01:07:52
    Re: Sort list of number to create hierarchy in gallery.

    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
    )
  • AJ_Z Profile Picture
    3,711 Super User 2024 Season 1 on 07 Jan 2022 at 10:22:50
    Re: Sort list of number to create hierarchy in gallery.

    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

     

     

  • AJ_Z Profile Picture
    3,711 Super User 2024 Season 1 on 05 Jan 2022 at 22:13:42
    Re: Sort list of number to create hierarchy in gallery.

    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 🙂

  • Usman2 Profile Picture
    124 on 05 Jan 2022 at 15:45:04
    Re: Sort list of number to create hierarchy in gallery.

    @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 05 Jan 2022 at 11:57:13
    Re: Sort list of number to create hierarchy in gallery.

    Let me know if my above suggestion works for you 🙂

  • Verified answer
    AJ_Z Profile Picture
    3,711 Super User 2024 Season 1 on 05 Jan 2022 at 11:56:44
    Re: Sort list of number to create hierarchy in gallery.

    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

     

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Tom Macfarlan – Community Spotlight

We are honored to recognize Tom Macfarlan as our Community Spotlight for October…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 752 Most Valuable Professional

#2
developerAJ Profile Picture

developerAJ 472

#3
Michael E. Gernaey Profile Picture

Michael E. Gernaey 358 Super User 2025 Season 2

Last 30 days Overall leaderboard
Loading complete