Filter and Display New Employees in Power Apps with Microsoft Graph

Many intranet portals need to display new employees. Let’s learn how to show a list of new employees who joined this year in a Power Apps application using the Microsoft Graph API.

First, we need to create a Microsoft Graph API query to find employees based on their joining date.

API

https://graph.microsoft.com/v1.0/users?$filter=employeeHireDate ge 2024-01-01T0:0:00Z&$count=true

Headers

Consistency level: eventual

When filtering by hire date, be sure to include $count=true as a parameter and set the ConsistencyLevel header to eventual.

With the basics covered, let’s start building a Power Apps application.

Create a new canvas app in Power Apps, and add a button, date-time picker, and gallery controls to the canvas screen.

S.No Control Name Property
1 Button btnGetUsers
2 Date Picker dtpStartDate
3 Date Picker dtpEndDate
4 Gallery glUsers
5 Text Label (Inside the Gallery Control) lblUserName

Then, Connect the Office 365 User data source to your app.

Data source

In the button's OnSelect property, add the following formula.

Set(
    varNewusers,
    Office365Users.HttpRequest(
        "https://graph.microsoft.com/v1.0/users?$filter=(employeeHireDate ge " & Text(
            dtpStartDate.SelectedDate,
            "yyyy-mm-ddThh:mm:ss"
        ) & "Z and employeeHireDate le " & Text(
            dtpEndDate.SelectedDate,
            "yyyy-mm-ddThh:mm:ss"
        ) & "Z )&$count=true&$select=displayName",
        "GET",
        "",
        {CustomHeader1: "Consistencylevel:eventual"}
    )
);
ClearCollect(
    varNewjoiners,
    Table(varNewusers.value)
);

In the OnSelect property, two variables are used: varNewusers and varNewjoiners.

  • varNewusers stores the response from the Microsoft Graph API.
  • varNewjoiners converts the retrieved response into an array of data.

Next, add a Text Label control inside the Gallery control and update its properties according to the table below.

Control Property Value
Button (btnGetUsers) Text Get Joiners
Gallery (glUsers) Items Varnewjoiners
Text Label (lblUserName) Text ThisItem.Value.displayName

Once you've completed all the steps above, run the application. In the app, click the 'Get Joiners' button. This will trigger a Microsoft Graph API call to filter users based on the EmployeeHireDate property using Office365Users.HTTPRequest. The display names of the filtered users will then appear in the Gallery control.

HTTPRequest


Similar Articles