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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to create a collec...
Power Apps
Answered

How to create a collection to retrieve all the departments from the office365user connector in a comobox?

(0) ShareShare
ReportReport
Posted on by 1,042

Hi,

How to create a collection to retrieve all the departments from the office365user connector in a comobox?

and using Distinct to get only the unique values and sort them using the Sort command.

Gr.P

Categories:
I have the same question (0)
  • mmbr1606 Profile Picture
    14,605 Super User 2025 Season 2 on at

    hey @PeKi72 

     

    you can try this:

    // Replace 'YourCollectionName' with the name you want to give to your collection
    ClearCollect(YourCollectionName, Office365Users.SearchUser({searchTerm: "", top: 999}).department);
    ClearCollect(SortedUniqueDepartments, Sort(Distinct(YourCollectionName, Value), Result, Ascending));
    

     

    Set its Items property to the collection that holds the sorted and unique departments, which is SortedUniqueDepartments in this example:

    SortedUniqueDepartments
    

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • CU16021406-1 Profile Picture
    1,042 on at

    Where should i put the ClearCollect sentences?

  • CU16021406-1 Profile Picture
    1,042 on at

    PeKi72_0-1709636734177.png

    I would like to leave the name YourCollectionName as it is. But i get an error !

     

    Gr. P

  • Yogesh Murugan Profile Picture
    443 Moderator on at

    Try this code

     

    ClearCollect(
     YourCollectionName,
     Office365Users.SearchUser({searchTerm:"",top:999}));
    
    ClearCollect(
     DepartmentCollection,
     YourCollectionName.Department
    );
    ClearCollect(
     SortedUniqueDepartments,Sort(Distinct(DepartmentCollection,Department),Value))
  • mmbr1606 Profile Picture
    14,605 Super User 2025 Season 2 on at

    what does the error say?

  • CU16021406-1 Profile Picture
    1,042 on at

    The problem is i do not know how to create a collection or am i even aloud to create a collection. Even as simple as this below i get an error:

     

    PeKi72_0-1709640047178.png

    P

     

  • CU16021406-1 Profile Picture
    1,042 on at

    Frustrating 😫

  • CU16021406-1 Profile Picture
    1,042 on at

    Found the error: the comma should be ;

     

  • CU16021406-1 Profile Picture
    1,042 on at

    Now the only thing i need is to get the Department values of the Office365users connector into that Collection.

    Which i have declared in the OnStart event of the app

     

    Collect(
        BookCollection;
        {
            BookName: "The Testaments";
            Author: "Margaret Atwood"
        }
    )
  • Verified answer
    mmbr1606 Profile Picture
    14,605 Super User 2025 Season 2 on at

    put the curser on the red underlined collection name and show me what the error says

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard