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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to sort on SharePo...
Power Apps
Unanswered

How to sort on SharePoint people column (show first the items where this people column is empty)

(0) ShareShare
ReportReport
Posted on by 96

I created a PowerApp from a SharePoint list. One of my columns is of the type "People or Group". I would like to sort the gallery with all the list items. I would like to show first the items where the people column is empty. I try this but it is not working:

 

Sort(
If(
/* filter on date */
IsEmpty(PersoonCombobox.SelectedItems),

Filter(
CoronaWerkplekRooster,
Datum <= Date(
Year(DatePicker1.SelectedDate),
Month(DatePicker1.SelectedDate),
Day(DatePicker1.SelectedDate)
),
Datum >= Date(
Year(DatePicker1.SelectedDate),
Month(DatePicker1.SelectedDate),
Day(DatePicker1.SelectedDate)
)
)

,
/* filter on user */
Filter(
CoronaWerkplekRooster,
Persoon.Email = PersoonCombobox.Selected.Email
)
),
/* sort on Persoon. Show the items without Persoon first */
Persoon.DisplayName,
Ascending

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @dreamsat 

    Consider the following formula:

    SortByColumns(
     Filter(
     AddColumns(
     CoronaWerkplekRooster,
     "persoonEmail", Persoon.Email,
     "persoonName", Persoon.DisplayName
     ),
     If(IsBlank(PersoonCombobox.Selected.Email),
     /* filter on date */
     Datum <= DatePicker1.SelectedDate &&
     Datum >= DatePicker1.SelectedDate,
     /* else - filter on user */
     persoonEmail = PersoonCombobox.Selected.Email
     )
     ),
     "persoonName",
     Ascending
    )

     

    This should give you what you need.

    Couple of things...The SelectedDate of your DatePicker is already a date.  There is no need to take the individual year, month and day to convert it back to a date.

    Also, this formula will always sort by person name.  If you wanted the sort to change based on if there is a name selected from person name to date, then you can consider this formula instead:

    SortByColumns(
     Filter(
     AddColumns(
     CoronaWerkplekRooster,
     "persoonEmail", Persoon.Email,
     "persoonName", Persoon.DisplayName
     ),
     If(IsBlank(PersoonCombobox.Selected.Email),
     /* filter on date */
     Datum <= DatePicker1.SelectedDate &&
     Datum >= DatePicker1.SelectedDate,
     /* else - filter on user */
     persoonEmail = PersoonCombobox.Selected.Email
     )
     ),
     If(IsBlank(PersoonCombobox.Selected.Email), "Datum", "persoonName"),
     Ascending
    )

    This will sort by date when no name is selected and by name when a name is selected.

     

    I hope this is helpful for you.

  • dreamsat Profile Picture
    96 on at

    @RandyHayes Great, the second script works. I just see something I didnt think about it before. Is it possible to sort on a second  column?

     

    I would like to see first the items where column "Persoon.DisplayName" and column "Externe Persoon" are both empty. After this I would like to see the items where column "Persoon.DisplayName" is empty and column "Externe Persoon" is filled. Something like this:

     

    SharePoint column "Externe Persoon" is of type single line of text.

     

    "Persoon.DisplayName"      |     Externe Persoon

    ""                                         |      ""

    ""                                         |      "test2"

    "test3"                                 |      "test3"

    "test4"                                 |      "test4" 

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @dreamsat 

    Yes, you can add additional columns to the formula:

     

    SortByColumns(
     Filter(
     AddColumns(
     CoronaWerkplekRooster,
     "persoonEmail", Persoon.Email,
     "persoonName", Persoon.DisplayName
     ),
     If(IsBlank(PersoonCombobox.Selected.Email),
     /* filter on date */
     Datum <= DatePicker1.SelectedDate &&
     Datum >= DatePicker1.SelectedDate,
     /* else - filter on user */
     persoonEmail = PersoonCombobox.Selected.Email
     )
     ),
     If(IsBlank(PersoonCombobox.Selected.Email), "Datum", "persoonName"),
     Ascending,
     "Externe Persoon", 
     Ascending
    )

     

  • dreamsat Profile Picture
    96 on at

    I modified yours like this but it is still not sorting like I expect:

     

    SortByColumns(
    Filter(
    AddColumns(
    CoronaWerkplekRooster,
    "persoonEmail", Persoon.Email,
    "persoonName", Persoon.DisplayName,
    "externePersoon", 'Externe persoon'
    ),
    If(IsBlank(PersoonCombobox.Selected.Email),
    /* filter on date */
    Datum <= DatePicker1.SelectedDate &&
    Datum >= DatePicker1.SelectedDate,
    /* else - filter on user */
    persoonEmail = PersoonCombobox.Selected.Email
    )
    ),
    If(IsBlank(PersoonCombobox.Selected.Email), "Datum", "persoonName"),
    Ascending,
    "externePersoon",
    Ascending
    )

     

    sorting issue.png

     

    I expect the green items as first.

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @dreamsat 

    Actually, based on what we put together before - what you are seeing is correct.  In that screen shot, you did not have a person selected, so your sort was by Date and then by the External name.

    If you select a person, you should see your sort as you want.

     

    We based the formula before on if a person was selected because that was how you had your original formula.

    If you always want it sorted by blank name and then blank external name as you mention, then get rid of the If statement that selects the Datum column if no person is selected in the SortBy and just make it persoonName.

     

  • dreamsat Profile Picture
    96 on at

    Hi @RandyHayes lets forget the if statement about the date picker and people picker. How to sort like I would like to have without the people picker? I removed the if statements:

     

    SortByColumns(
    Filter(
    AddColumns(
    CoronaWerkplekRooster,
    "persoonEmail", Persoon.Email,
    "persoonName", Persoon.DisplayName,
    "externePersoon", 'Externe persoon'
    ),
    /* filter on date */
    Datum <= DatePicker1.SelectedDate &&
    Datum >= DatePicker1.SelectedDate
    ),
    "persoonName",
    Ascending,
    "externePersoon",
    Ascending
    )

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @dreamsat 

    Sorry I didn't get the question in that...is that working or not producing what you want?

  • dreamsat Profile Picture
    96 on at

    I would like to sort as follow. I am able to remove the if statement if it will be easier to implement this expected sorting.

     

    "Persoon.DisplayName"      |     Externe Persoon

    ""                                         |      ""

    ""                                         |      "test2"

    "test3"                                 |      "test3"

    "test4"                                 |      "test4" 

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @dreamsat 

    I guess my question is that you posted a formula last and I didn't see a question.  My question then is, what are you seeing now with that formula?  How is it sorting and how is it not sorting as you want.  I know where you're trying to get, but that formula should do it...where is it going wrong?

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 1,045

#2
Valantis Profile Picture

Valantis 675

#3
11manish Profile Picture

11manish 592

Last 30 days Overall leaderboard