Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Unanswered

Getting Direct Reports (V2)

(1) ShareShare
ReportReport
Posted on by

Hi,

 

I am quite new to Power Apps and learning on the go. I recently came across Direct reports (v2) using the Office365 property. I am able to get all the DirectReports of the given user. However, this does not satisfy my requirements. What I wanted is to do the following.

Imagine the organization chart are as follows:

A: Managing director
B: Technical director
C: product manager.

Here C reports to B and B reports to A. If I get the directReports of B I will get C. Similarly, If I get the direct reports of A I will get B. However, I want both B and C to be shown if I fetch the direct reports of A.

How can I achieve that using Power Apps?

Thanks in Advance!

  • killerBee15 Profile Picture
    on at
    Re: Getting Direct Reports (V2)

    Thank you for your response! I will try this and get back to you.

     

  • michalparal222 Profile Picture
    86 on at
    Re: Getting Direct Reports (V2)

    Hi @killerBee15 ,

     

    I am no expert too, but I have tried and this was my result, the only limitation is that the number of levels down the structure depends on how many times you copy the part after //  ****Start again**** I did not succeeded to do it in some form of a loop. Anyway it works, so mark my solution, if it is enough for you.

     

    // First set of direct reports
    Set(varResult, Office365Users.DirectReportsV2(TextInputCanvas2.Value));
    ClearCollect(colAllTemp,varResult.value);
    
    // Filter empty rows and first row 
    ClearCollect(colAll, Filter(colAllTemp, !IsBlank(accountEnabled)));
    
    //Get results for first set of direct
    ClearCollect(colAllTemp, ForAll(colAll,Office365Users.DirectReportsV2(ThisRecord.userPrincipalName)));
    ClearCollect(colMergedResults, []); // define new empty collection
    ForAll(colAllTemp,Collect(colMergedResults, ThisRecord.value) );
    
    //Final collection
    Collect(colAll,colMergedResults);
    ClearCollect(colAllFinal, ForAll(Distinct(colAll, ThisRecord), Value)); // Set only uniqe values
    ClearCollect(colAllFinalFiltered, Filter(colAllFinal, !IsBlank(accountEnabled)));
    
    
    // ****Start again**** (third level)
    ClearCollect(colAllTemp, ForAll(colAllFinalFiltered,Office365Users.DirectReportsV2(ThisRecord.userPrincipalName)));
    Clear(colMergedResults);
    ForAll(colAllTemp,Collect(colMergedResults, ThisRecord.value) );
    
    //Final collection
    Collect(colAll,colMergedResults);
    ClearCollect(colAllFinal, ForAll(Distinct(colAll, ThisRecord), Value)); // Set only uniqe values
    ClearCollect(colAllFinalFiltered, Filter(colAllFinal, !IsBlank(accountEnabled)));
    
    // ****Start again**** (fourth level)
    ClearCollect(colAllTemp, ForAll(colAllFinalFiltered,Office365Users.DirectReportsV2(ThisRecord.userPrincipalName)));
    Clear(colMergedResults);
    ForAll(colAllTemp,Collect(colMergedResults, ThisRecord.value) );
    
    //Final collection
    Collect(colAll,colMergedResults);
    ClearCollect(colAllFinal, ForAll(Distinct(colAll, ThisRecord), Value));

     

    This way I counted 1286 users in our org.  🙂

     

    Regards,

    Michal Páral

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,609 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,946 Most Valuable Professional

Leaderboard