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 / 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,068

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:
  • mmbr1606 Profile Picture
    14,629 Super User 2026 Season 1 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,068 on at

    Where should i put the ClearCollect sentences?

  • CU16021406-1 Profile Picture
    1,068 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
    451 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,629 Super User 2026 Season 1 on at

    what does the error say?

  • CU16021406-1 Profile Picture
    1,068 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,068 on at

    Frustrating 😫

  • CU16021406-1 Profile Picture
    1,068 on at

    Found the error: the comma should be ;

     

  • CU16021406-1 Profile Picture
    1,068 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,629 Super User 2026 Season 1 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

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