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

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Filtering Office365Use...
Power Apps
Unanswered

Filtering Office365Users by Department

(1) ShareShare
ReportReport
Posted on by 226 Moderator

Not sure if there is a way, but I am hoping.

I need to filter Office365Users() by department so that we are left with a list of approximately 150 employees in a specific group.

My other problem is I need to have the Filter based on the department containing 'facility'.

If I use this code, I can use a search box to only find employees in the department but we do not want to type a name, I just want to build a collection of all employees in the department.

Filter(
 Office365Users.SearchUser({searchTerm: Trim(TextInput1.Text)}), "facility" in Department
)

 

The issue I have come across is the Filter() commands want to look for First or Last Name and not just filter by department. Any thoughts or workarounds?

Cheers

Categories:
I have the same question (0)
  • Pro_User_365 Profile Picture
    546 on at

    Hi @Hack-7 ,

     

    To filter Office365Users() by department containing 'facility' and build a collection of all employees in that department, you can use the following workaround:

     

     
    ClearCollect(
     EmployeesInFacilityDepartment,
     Filter(
     Office365Users.SearchUser({ searchTerm: "" }),
     "facility" in Department
     )
    )

     

    1. ClearCollect: This function clears any previous data in the collection (if any) and then collects new data into it.

    2. EmployeesInFacilityDepartment: Replace this with the name you want to give to your collection.

    3. Filter: It filters the Office365Users() list by checking if "facility" is in the Department.

      • Note that we use Office365Users.SearchUser({ searchTerm: "" }) to retrieve all users without a search term, effectively getting all users.

    This code will create a collection called EmployeesInFacilityDepartment that contains all employees in the department containing 'facility'. You can then use this collection for further operations or display purposes as needed.

    Note: After receiving the answer, if you think it's helpful, please consider accepting it. 😊 Regards! Ali Shahzad
     
     
  • Hack-7 Profile Picture
    226 Moderator on at

    @Pro_User_365 That code produces an empty collection for me.

  • Pro_User_365 Profile Picture
    546 on at

    Hi @Hack-7 , 

    If the provided code results in an empty collection, it may be due to the SearchUser function not supporting the direct filtering by department. A workaround could be to retrieve all users and then process the collection to filter by department:

    ClearCollect(
     AllUsers,
     Office365Users.SearchUser({ searchTerm: "" })
    );
    
    ClearCollect(
     EmployeesInFacilityDepartment,
     Filter(
     AllUsers,
     "facility" in Department
     )
    );

    This two-step process creates an initial collection of all users and then filters that collection to include only those in the 'facility' department. However, be mindful of potential performance issues when retrieving large numbers of users.

    Note: If you find this solution helpful, please consider accepting it. 😊
     
     

     

  • Hack-7 Profile Picture
    226 Moderator on at

    @Pro_User_365 , Thanks for the help on this so far.  

     

    The issue is there are 5000+ employees, so I assume I will get deligation issues

  • Pro_User_365 Profile Picture
    546 on at

    @Hack-7 ,

    1. Adjust the Data Source: If possible, modify your SharePoint list or data source to have a view that filters the 'facility' department. PowerApps can delegate filter operations on SharePoint views.

    2. Batch Processing: Retrieve users in batches that your app can handle without hitting delegation limits. Use a loop with incremental filtering based on other non-delegable fields that are indexed, like UserID or CreatedDate.

    3. Azure Functions: Utilize Azure Functions to handle the data retrieval and filtering server-side, then return the result to PowerApps.

    4. Power Automate: Though you want to avoid flows, a Power Automate flow could run on a schedule, filter the users, and update a SharePoint list that PowerApps could read without delegation issues.

    5. Index Columns: Ensure the 'Department' column is indexed in SharePoint to improve performance and potentially avoid delegation issues when filtering.

  • Hack-7 Profile Picture
    226 Moderator on at

    @Pro_User_365 interesting thoughts.

     

    Question, Not liking the Flow idea, but how would you build a Flow for all users, then filter it by department?

  • Pro_User_365 Profile Picture
    546 on at

    Hi @Hack-7 ,

    To implement a Power Automate (formerly known as Microsoft Flow) solution that filters users by department and updates a SharePoint list, follow these steps:

    1. Create a New Flow:

      • Go to the Power Automate website.
      • Sign in with your Microsoft account.
      • Click on "Create" to start creating a new flow.
    2. Choose a Trigger:

      • Select a trigger that suits your needs. In this case, you might use a scheduled trigger to run the flow at specific intervals (e.g., daily or weekly).
    3. Add an Action to Filter Users:

      • After the trigger, add an action that retrieves all the users you want to filter. This could be from an Office 365 Users connector or another relevant data source.
    4. Apply the Filter:

      • Use a filtering action or condition to filter the users by the 'Department' attribute. Ensure that you only select users from the 'facility' department.
    5. Update a SharePoint List:

      • Add an action to update a SharePoint list. Specify which SharePoint site and list you want to update.
    6. Map User Data to SharePoint Columns:

      • Map the user data you retrieved in step 3 to the appropriate columns in your SharePoint list.
    7. Save and Test the Flow:

      • Save the flow and test it to ensure that it successfully retrieves users, filters them by department, and updates the SharePoint list.
    8. Set a Schedule:

      • If you're using a scheduled trigger, configure the schedule according to your requirements (e.g., daily at a specific time).
    9. Turn On the Flow:

      • Once you've tested and configured the flow, turn it on. It will now run based on the schedule you've defined.
    10. PowerApps Integration:

      • In your PowerApps app, you can read data from the updated SharePoint list without delegation issues because the data is pre-filtered by the flow.

    By following these steps, you can create a Power Automate flow that periodically filters users by department and updates a SharePoint list. Your PowerApps app can then retrieve data from this list without delegation concerns, even with a large number of employees.

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!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 254 Most Valuable Professional

#2
Kalathiya Profile Picture

Kalathiya 211 Super User 2026 Season 1

#3
VASANTH KUMAR BALMADI Profile Picture

VASANTH KUMAR BALMADI 195

Last 30 days Overall leaderboard