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 / Help with sorting/filt...
Power Apps
Unanswered

Help with sorting/filtering on a gallery using office365users

(0) ShareShare
ReportReport
Posted on by 4

Hi I'm a newbie and am having problems joining two conditions together into the Items property of a gallery.  Both work independently but I'm getting myself in a muddle applying them both to the gallery.

 

This condition checks if the logged in user is in the Business Readiness department and shows all sharepoint items in the gallery.  If false it only displays records the logged in user has created or records created by anyone with the same department as the logged in user.

If(Office365Users.MyProfile().Department = "60152 GTO - Business Readiness Protection",Filter('Contact Business Readiness','Created By'.Email=Office365Users.MyProfile().Mail || Office365Users.MyProfile().Department= 'Created By'.Department),Filter('Contact Business Readiness',StartsWith('Created By'.DisplayName,TextSearchBox1.Text)))
 
This condition is a search using a filter on the sharepoint list on the status or created by columns.
Filter('Contact Business Readiness', StartsWith('Status'.Value, TextSearchBox1.Text)  ||  StartsWith('Created By'.Department, TextSearchBox1.Text))
 
Regardless of the outcome of the first condition I want the user to be able to be able to use the TextSearchBox1 to show the items they search for.
 
Any help is greatly appreciated. 
Categories:
  • Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @mcdryburn - is this what you're trying to do?

    With(
     {
     _data: If(
     Office365Users.MyProfile().Department = "60152 GTO - Business Readiness Protection",
     'Contact Business Readiness',
     Filter(
     'Contact Business Readiness',
     'Created By'.Email = Office365Users.MyProfile().Mail || Office365Users.MyProfile().Department = 'Created By'.Department
     )
     )
     },
     Filter(
     _data,
     StartsWith(
     'Created By'.DisplayName,
     TextSearchBox1.Text
     )
     )
    
  • mcdryburn Profile Picture
    4 on at

    Thanks for this, i moved away from the approach above and instead am using 4 dropdown options now but am still facing an issue .  I've got the dropdowns working to filter what is shown in the gallery but can't get the other pasrt of the function to restrict the records shown based on the logged in user being

    Office365Users.MyProfile().Department = "60152 GTO - Business Readiness Protection"

    in which case they should be able to see all the records in the gallery (with filters from the dropdowns aplied if any have been slected) or if not 

    Office365Users.MyProfile().Department = "60152 GTO - Business Readiness Protection"

     then they should be able to see their own created items or any created items from anyone in their department 

    Filter(
     'Contact Business Readiness',
     'Created By'.Email = Office365Users.MyProfile().Mail || Office365Users.MyProfile().Department = 'Created By'.Department
     )

    (again if any dropdown(s) selected these filters should also be applied).

    i've tried a clearcollect 'onvisible'of the main screen:

     ClearCollect(_Data,
        Filter(
            'Contact Business Readiness',
            'Created By'.Email = Office365Users.MyProfile().Mail || Office365Users.MyProfile().Department = _varUserDept)
            );
            If(Office365Users.MyProfile().Department = "60152 GTO - Business Readiness Protection",
            ClearCollect(_Data,'Contact Business Readiness'))


    with the galler items set as


    Filter(
        _Data,
        IsBlank(Dropdown2.Selected.Value) || BRArea.Value = Dropdown2.Selected.Value,
        IsBlank(Dropdown2_1.Selected.Value) || Status.Value = Dropdown2_1.Selected.Value,
        IsBlank(Dropdown1.Selected.Value) || 'Created By'.DisplayName = Dropdown1.Selected.Value,
        IsBlank(Dropdown1_1.Selected.Value) || 'Assigned to'.DisplayName = Dropdown1_1.Selected.Value
    )
     
    This allows the dropdown options to filter the items displayed but a non 'Business Readiness Protection' user sees records that aren't their own or from someone else in their department.  Any help appreaciated.  Thanks
  • kelseytran Profile Picture
    292 on at

    Hi @mcdryburn ,

     

    Try using this code to combine both the conditions in your Items property:

     

    If(
     Office365Users.MyProfile().Department = "60152 GTO - Business Readiness Protection",
     If(
     IsBlank(TextSearchBox1.Text),
     Filter('Contact Business Readiness', 'Created By'.Email = Office365Users.MyProfile().Mail || 'Created By'.Department = Office365Users.MyProfile().Department),
     Filter(
     'Contact Business Readiness',
     StartsWith('Status'.Value, TextSearchBox1.Text) ||
     StartsWith('Created By'.Department, TextSearchBox1.Text)
     )
     ),
     If(
     IsBlank(TextSearchBox1.Text),
     Filter('Contact Business Readiness', 'Created By'.Email = Office365Users.MyProfile().Mail),
     Filter(
     'Contact Business Readiness',
     StartsWith('Status'.Value, TextSearchBox1.Text) ||
     StartsWith('Created By'.Department, TextSearchBox1.Text)
     )
     )
    )

     

    The outer If statement checks if the logged-in user is in the "60152 GTO - Business Readiness Protection" department. If true, it applies the corresponding filter conditions; otherwise, it applies the filter conditions for users not in that department.

    Within each branch of the outer If statement, there's another If statement to handle the search functionality. If the TextSearchBox1 is empty, it applies the filter without search criteria; otherwise, it applies the filter with the search criteria.

    ------------------------------------------------------------------------------------------------------------------------------
    If I answered your question, please accept my post as a solution and if you liked my response, please give it a thumbs up.

    Thanks!

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 354 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 330

#3
Mohsin Ali Profile Picture

Mohsin Ali 232

Last 30 days Overall leaderboard