The code you posted is doing exactly what you have asked. Assuming you are using
UserDisplay in your
DisplayFields in the Combo Box, I have added some notes below. I suspect you have a lot of missing information in your Entra data.
With(
{
users: Office365Users.SearchUser(
{
SearchTerm: Self.SearchText,
top: 100
}
)
}, //grab the list of users matching the user input
SortByColumns(
AddColumns(
Filter( //now filter it
users,
!IsBlank(
Coalesce( //make sure the Mail or UserPrincipalName contains data
Mail,
UserPrincipalName //this should never be blank, so the filter is probably a waste of time
)
) && AccountEnabled //suggestion to add
),
UserEmail, //Add a column of either the Mail or UserPrincipalName
Coalesce(
Mail, //Mail also should never be blank
UserPrincipalName
),
UserDisplay, //Add a column to display in the box
Coalesce( //Coalesce can contain multiple item and finds the first non-blank
DisplayName
Mail,
UserPrincipalName
)
),
"UserDisplay",
SortOrder.Ascending
)
)
So I suggest this is all you need
With(
{
users: Office365Users.SearchUser(
{
SearchTerm: Self.SearchText,
top: 100
}
)
},
SortByColumns(
AddColumns(
Filter(
users,
AccountEnabled
),
UserEmail,
Coalesce(
Mail,
UserPrincipalName
),
UserDisplay,
Coalesce(
DisplayName
Mail,
UserPrincipalName
)
),
"UserDisplay",
SortOrder.Ascending
)
)
which will find the first non-blank value from (in order), DisplayName, Mail, UserPrincipalName.
Please ✅ Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like ♥
Visit my blog Practical Power Apps LinkedIn