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 / Need help with sorting...
Power Apps
Answered

Need help with sorting people column

(0) ShareShare
ReportReport
Posted on by 6,048 Super User 2024 Season 1

10.png

Above is my gallery.

Below is my item property code:

SortByColumns(
If(
!IsBlank(SearchBox.Text),
Search(
Filter(
Candidate_Leads,
OfficeLoacation.Value = drpOffice.Selected.Value || drpOffice.Selected.Value = "All",
SourceOfMarketing.Value = drpSource.Selected.Value || drpSource.Selected.Value = "All",
Status.Value = drpStatus.Selected.Value || drpStatus.Selected.Value = "All",
Created >= dtfromdate.SelectedDate && Created <= DateAdd(
dttodate.SelectedDate,
1,
Days
)
),
SearchBox.Text,
"FullName",
"Email",
"Phone"
),
Filter(
Candidate_Leads,
OfficeLoacation.Value = drpOffice.Selected.Value || drpOffice.Selected.Value = "All",
SourceOfMarketing.Value = drpSource.Selected.Value || drpSource.Selected.Value = "All",
Status.Value = drpStatus.Selected.Value || drpStatus.Selected.Value = "All",
Created >= dtfromdate.SelectedDate && Created <= DateAdd(
dttodate.SelectedDate,
1,
Days
)
)
),
varSort,
If(
SortDescending1,
Descending,
Ascending
)
)

=================================

This is what i did to all sorting arrows:

========================

UpdateContext({varSort :"FirstName"});
UpdateContext({SortDescending1:false});

================================

I was searching the forum for solutions and someone gave below code:

 

SortByColumns(
 AddColumns(
 SharePoint_List,
 "PersonsName",
 PersonColumn.DisplayName
 ),
 "PersonsName"
)

My problem is, How to add this people column sorting code into my existing item code. Please help. 

Categories:
  • v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @zmansuri ,

     

    Please try below:

    1\ Modify the variables on the sorting arrows:

    UpdateContext({varSort :"PersonName"});
    UpdateContext({SortDescending1:false});

     

    2\ apply below formula on the Items of the Gallery:

    SortByColumns(
    If(
    !IsBlank(SearchBox.Text),
    Search(
    Filter(
    AddColumns(
     Candidate_Leads,
     "PersonsName",
     PersonColumn.DisplayName
     ),
    OfficeLoacation.Value = drpOffice.Selected.Value || drpOffice.Selected.Value = "All",
    SourceOfMarketing.Value = drpSource.Selected.Value || drpSource.Selected.Value = "All",
    Status.Value = drpStatus.Selected.Value || drpStatus.Selected.Value = "All",
    Created >= dtfromdate.SelectedDate && Created <= DateAdd(
    dttodate.SelectedDate,
    1,
    Days
    )
    ),
    SearchBox.Text,
    "PersonName",
    "Email",
    "Phone"
    ),
    Filter(
    AddColumns(
     Candidate_Leads,
     "PersonsName",
     PersonColumn.DisplayName
     ),
    OfficeLoacation.Value = drpOffice.Selected.Value || drpOffice.Selected.Value = "All",
    SourceOfMarketing.Value = drpSource.Selected.Value || drpSource.Selected.Value = "All",
    Status.Value = drpStatus.Selected.Value || drpStatus.Selected.Value = "All",
    Created >= dtfromdate.SelectedDate && Created <= DateAdd(
    dttodate.SelectedDate,
    1,
    Days
    )
    )
    ),
    varSort,
    If(
    SortDescending1,
    Descending,
    Ascending
    )
    )

     

    Hope this helps.

     

    Best regards,

    Community Support Team _ Jeffer Ni
    If this post helps, then please consider Accept it as the solution to help the other members find it.

     

     

  • zmansuri Profile Picture
    6,048 Super User 2024 Season 1 on at
    SortByColumns(
    If(
    !IsBlank(SearchBox.Text),
    Search(
    Filter(
    AddColumns(
    Candidate_Leads,
    "PersonsName",
    AssignTo.DisplayName
    ),
    OfficeLoacation.Value = drpOffice.Selected.Value || drpOffice.Selected.Value = "All",
    SourceOfMarketing.Value = drpSource.Selected.Value || drpSource.Selected.Value = "All",
    Status.Value = drpStatus.Selected.Value || drpStatus.Selected.Value = "All",
    Created >= dtfromdate.SelectedDate && Created <= DateAdd(
    dttodate.SelectedDate,
    1,
    Days
    )
    ),
    SearchBox.Text,
    "PersonName",
    "Email",
    "Phone"
    ),
    Filter(
    AddColumns(
    Candidate_Leads,
    "PersonsName",
    AssignTo.DisplayName
    ),
    OfficeLoacation.Value = drpOffice.Selected.Value || drpOffice.Selected.Value = "All",
    SourceOfMarketing.Value = drpSource.Selected.Value || drpSource.Selected.Value = "All",
    Status.Value = drpStatus.Selected.Value || drpStatus.Selected.Value = "All",
    Created >= dtfromdate.SelectedDate && Created <= DateAdd(
    dttodate.SelectedDate,
    1,
    Days
    )
    )
    ),
    varSort,
    If(
    SortDescending1,
    Descending,
    Ascending
    )
    )

    I just changed the person column name in your given code. Which in my case is "AssignTo". It shows error. 

    "The function search has some invalid arguments".

    what should i do?

  • v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @zmansuri ,

     

    Sorry for my unthought-out codes. The question is what's the main purpose that add the display name into the sort function? Would you like to search the full name of Assign To column?

     

    If so, below is the correct formula:

    SortByColumns(
    If(
    !IsBlank(SearchBox.Text),
    Search(
    AddColumns(
    Filter(
    Candidate_Leads,
    OfficeLoacation.Value = drpOffice.Selected.Value || drpOffice.Selected.Value = "All",
    SourceOfMarketing.Value = drpSource.Selected.Value || drpSource.Selected.Value = "All",
    Status.Value = drpStatus.Selected.Value || drpStatus.Selected.Value = "All",
    Created >= dtfromdate.SelectedDate && Created <= DateAdd(
    dttodate.SelectedDate,
    1,
    Days
    )
    ),
    "PersonsName",
    ThisRecord.AssignTo.DisplayName
    ),
    SearchBox.Text,
    "PersonName",
    "Email",
    "Phone"
    ),
    AddColumns(
    Filter(
    Candidate_Leads,
    OfficeLoacation.Value = drpOffice.Selected.Value || drpOffice.Selected.Value = "All",
    SourceOfMarketing.Value = drpSource.Selected.Value || drpSource.Selected.Value = "All",
    Status.Value = drpStatus.Selected.Value || drpStatus.Selected.Value = "All",
    Created >= dtfromdate.SelectedDate && Created <= DateAdd(
    dttodate.SelectedDate,
    1,
    Days
    )
    ),
    "PersonsName",
    ThisRecord.AssignTo.DisplayName
    ),
    varSort,
    If(
    SortDescending1,
    Descending,
    Ascending
    )
    )

     

    Best regards,

    Community Support Team _ Jeffer Ni
    If this post helps, then please consider Accept it as the solution to help the other members find it.

  • zmansuri Profile Picture
    6,048 Super User 2024 Season 1 on at

    Above code gives the following error.

    All i want is sort "AssignTo" column in my powerapps gallery. Which is people type column in sharepoint.

    11.png

  • Verified answer
    zmansuri Profile Picture
    6,048 Super User 2024 Season 1 on at

    Finally This Code worked. I sorted by two columns

    1. AssignTo - Which is people type column in sharepoint.

    2. Status - Which is choice type column in sharepoint.

    =========================================

    SortByColumns(
    If(
    !IsBlank(SearchBox.Text),
    Search(
    AddColumns(
    Filter(
    Candidate_Leads,
    Year.Value = drpYear.Selected.Value,
    Month.Value = drpMonth.Selected.Value,
    OfficeLoacation.Value = drpOffice.Selected.Value || drpOffice.Selected.Value = "All",
    SourceOfMarketing.Value = drpSource.Selected.Value || drpSource.Selected.Value = "All",
    Status.Value = drpStatus.Selected.Value || drpStatus.Selected.Value = "All",
    Created >= dtfromdate.SelectedDate && Created <= DateAdd(
    dttodate.SelectedDate,
    1,
    Days
    )
    ),
    "AssignToTxt",
    AssignTo.DisplayName,"StatusTxt",Status.Value
    ),
    SearchBox.Text,
    "FullName",
    "Email",
    "Phone"
    ),
    AddColumns(
    Filter(
    Candidate_Leads,
    Year.Value = drpYear.Selected.Value,
    Month.Value = drpMonth.Selected.Value,
    OfficeLoacation.Value = drpOffice.Selected.Value || drpOffice.Selected.Value = "All",
    SourceOfMarketing.Value = drpSource.Selected.Value || drpSource.Selected.Value = "All",
    Status.Value = drpStatus.Selected.Value || drpStatus.Selected.Value = "All",
    Created >= dtfromdate.SelectedDate && Created <= DateAdd(
    dttodate.SelectedDate,
    1,
    Days
    )
    ),
    "AssignToTxt",
    AssignTo.DisplayName,"StatusTxt",Status.Value
    )
    ),
    varSort,
    If(
    SortDescending1,
    Descending,
    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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 397 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 354

#3
WarrenBelz Profile Picture

WarrenBelz 232 Most Valuable Professional

Last 30 days Overall leaderboard