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 / Creating a PowerApps C...
Power Apps
Answered

Creating a PowerApps Collection: Filtering Employees by Multiple Managers

(0) ShareShare
ReportReport
Posted on by 10

Hello.

I need to create a Collection with the employees that respond to a few managers.

I was already able to create a Collection with all the employees that respond to one manager, as the code bellow:

ClearCollect(
 Collection,
 Office365Users.DirectReports("manager1@company.com")
);

 

But I need to do it for more than 1 manager in a list of managers' emails, such as:

ClearCollect(EmailList, ["manager1@company.com", "manager2@company.com", "manager3@company.com"])

 

 

So I need to iterate in this EmailList and put all the information regarding the employees in a Collection. How can I do it, please?

I am trying to use ForAll, but I couldn't find the right way.



Thank you in advance...

BR

Categories:
  • RajnishMahaseth Profile Picture
    58 on at

    To achieve this, you can indeed use the `ForAll` function to iterate through the list of manager emails and collect employees for each manager. Here's how you can do it:

    Assuming you have the `EmailList` collection with the list of manager emails, and you want to collect employees for each manager into the `Collection`:

    ClearCollect(
    EmailList,
    ["manager1@company.com", "manager2@company.com", "manager3@company.com"]
    );

    ClearCollect(Collection, []); // Initialize an empty collection

    ForAll(
    EmailList,
    {
    var managerEmail = ThisRecord.Value; // Current manager email
    var employees = Office365Users.DirectReports(managerEmail); // Get employees for this manager
    Collect(Collection, employees); // Add employees to the main collection
    }
    );

    ```

    In this example, the `ForAll` function iterates through each manager's email in the `EmailList` collection. For each manager, it fetches their direct reports using `Office365Users.DirectReports` and adds those employees to the main `Collection` using the `Collect` function.

    By the end of this process, the `Collection` will contain all employees from all managers in a single collection.

    Remember to replace `manager1@company.com`, `manager2@company.com`, etc., with actual manager email addresses in your application.

  • MisterGeZeCe Profile Picture
    10 on at

    I am sorry, but this answer was taken from a ChatBot.
    I asked the question less than 1 minute ago, and this doesnt help...

  • Verified answer
    Prabhakar_S Profile Picture
    735 Moderator on at

    Hi @MisterGeZeCe ,

     

    Please try this formula,

     

    ClearCollect(EmailList, 
    ["manager1@company.com", "manager2@company.com", "manager3@company.com"]
    );

    ClearCollect(EmployeeCollection, {});

    ForAll(
    EmailList,
    Collect(
    EmployeeCollection,
    Office365Users.DirectReports(EmailList[@Value])
    ));

     

    This EmployeeCollection will store the employee data. 

     

    Inside the ForAll loop: EmailList[@Value] gets the current manager's email.

     

    Thanks!!!

  • MisterGeZeCe Profile Picture
    10 on at

    Thank you @Prabhakar_S , that works as a charm. 

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

#2
WarrenBelz Profile Picture

WarrenBelz 191 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 167

Last 30 days Overall leaderboard