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 / SortByColumn by Choice...
Power Apps
Answered

SortByColumn by Choice Field + Filter by Person + Filter by Search Box

(0) ShareShare
ReportReport
Posted on by 14

Could anyone help me with the syntax to do a complex sort+multiple filter expression?

 

I have a simple SharePoint list with 3 pertinent fields: 1) Employee (Person); 2) Date of Week Worked (Choice & actual name is 'Monday_x0020_of_x0020_Week_x0020'); and, 3) Title (Single Line of Text).

 

I need to: 1) filter by the logged in user using 'Employee'; filter by the 'Title' field (if entered), and sort by the 'Date of Week Worked' ascending.

 

My feeble--incomplete--attempt looks like this so far. 

 

SortByColumns(Filter([AddColumns([@'Time Tracker'],PersonsName,Employee.DisplayName), StartsWith(Title, TextSearchBox1.Text)), "PersonsName", If(SortDescending1, Descending, Ascending))

 

2021-07-01_16h54_43.png

 

Categories:
  • v-qiaqi@microsoft.com Profile Picture
    Microsoft Employee on at

    Hi @jerrylanejohns

    Do you want to filter the Employee column firstly and Title search text, finally sort by 'Monday_x0020_of_x0020_Week_x0020')?

    Could you please share a bit more about the scenario?

    Try as below:

    SortByColumns(
     AddColumns(
     Filter(
     'Time Tracker',
     Employee.Email = User().Email || StartsWith(
     Title,
     TextSearchBox1.Text
     )
     ),
     "DateTex", // Note that you should use AddColumns() for the Choice filed
     "MondayOfWeek"
     ),
     "DateTex",
     Ascending
    )
  • jerrylanejohns Profile Picture
    14 on at

    Hi! Thanks for your reply.

     

    I have a SP list called "Time Tracker" that is used to record weekly time cards for employees. The time card consists of an Employee (Person that creates the item in the list), Activity (Title field), Date of Week Worked (Choice field), and numeric fields (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, and Sunday) for the person to enter their time for each day of the week. Each time card starts on a Monday, so I have a choice column with a list of dates for each Monday of the year.

     

    In the app, an employee can enter new time cards; in this use case, the Person field would be defaulted to the current user. The employee would select a date from the dropdown and enter the hours for each day of the week, beginning with Monday.

     

    When browsing in the gallery (which is where I need to use this complex expression), the user should only see their items, i.e. items in the SP that they created (Employee=Current User). Optionally, the user could search by the Activity (Title) field to find a previous entry that was entered by that employee. So, the app is always limited to working with the SP items created by the current user.

     

    Finally, the browsing gallery list would be sorted by the time card's date that was selected from the choice column when the SP item was created.

     

    Thanks for your help!!!

  • v-qiaqi@microsoft.com Profile Picture
    Microsoft Employee on at

    Hi @jerrylanejohns

    Have you tried my solution?

    Could you please try it and give some feed back if there is anything wrong.

  • jerrylanejohns Profile Picture
    14 on at

    Thank you so much for your help. Adding the column and the filtering worked! However, when I select an item on the BrowseGallery1, the DetailForm1 gives an error. It doesn't seem to recognize the new data expression result. I've attached screenshots showing the error.

     

    Thanks again for all of your help!BrowseGallery1BrowseGallery1

     

    DetailForm1DetailForm1

    BrowseGallery1BrowseGallery1

     

    DetailForm1DetailForm1

     

  • Verified answer
    v-qiaqi@microsoft.com Profile Picture
    Microsoft Employee on at

    Hi @jerrylanejohns,

    The reason why you have this error is because you put different data source into Gallery and Detail Form.

    Just set the DataSource property of the DetailForm as below:

    SortByColumns(
     AddColumns(
     Filter(
     'Time Tracker',
     Employee.Email = User().Email || StartsWith(
     Title,
     TextSearchBox1.Text
     )
     ),
     "DateTex", // Note that you should use AddColumns() for the Choice filed
     'MondayOfWeek'.Value
     ),
     "DateTex",
     Ascending
    )

    Please keep the data source same between Gallery and Detail Form

     

  • jerrylanejohns Profile Picture
    14 on at

    Hi again. I followed your advice and made the data sources the same. So now, when I click on an item on the BrowseGallery, the DetailForm shows the fields for that item.

     

    However, I get a message on the DetailForm that says "This form is not connected to any data".

     

    Am I correct that when I use "AddColumn" in the data source, that the app is not connected directly to the SP list any longer?

     

    Thanks.

  • Verified answer
    WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    @jerrylanejohns ,

    Do the following - on the OnSelect of your Gallery

    Set(gblID,ThisItem.ID);
    Navigate(YourFormScreen)

    The Item of your Form

    LookUp(
     YourListName,
     ID=gblID
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 393 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 278 Most Valuable Professional

Last 30 days Overall leaderboard