I currently have a gallery where I'm showing a list of Office365 users which can be filtered based on search criteria. I'd like to limit this list to just Office365 users whose email addresses exists in a table.
How can I do this?
I thought about using Filter(Office365Users.SearchUser({searchTerm:SearchTerm.txt}), Formula), but I wasn't sure how to search against a list in the Formula.
Thanks in advance for any help.
Solved! Go to Solution.
Hi @sjlee
So lets say you have a collection of user emails like
ClearCollect(colUser,{Email:"reza@rdorrani.onmicrosoft.com"})
then you could use the formula
Filter((Office365Users.SearchUser({searchTerm: SearchTerm.Text})),Mail in colUser)
Regards,
Reza Dorrani
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi @sjlee
So lets say you have a collection of user emails like
ClearCollect(colUser,{Email:"reza@rdorrani.onmicrosoft.com"})
then you could use the formula
Filter((Office365Users.SearchUser({searchTerm: SearchTerm.Text})),Mail in colUser)
Regards,
Reza Dorrani
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Reza,
Thanks for your response. If my collection has three fields (name, ID and email), do I need to specify which column to search in the Filter?
I realized that the collection can only have one column if used in this manner, so I adjusted it.
My collection is being loaded correctly, but for some reason no results are being returned with the Filter. Any ideas what could be causing the email addresses not to match? I've tried adding TrimEnds to strip out any blank spaces, but still no success.
I would suggest you do something like this:
create a collection to test your email addresses, we can even have more than one column. This collection represents your table.
ClearCollect(MyEmailCollection, {mailAddress:"email1@hotmail.com",id:1},{mailAddress:"email2@hotmail.com",id:2});
then test your filter and load it into a new collection
ClearCollect(MyFilteredEmailCollection, Filter(Office365Users.SearchUser({searchTerm:"Luke"}),Mail in MyEmailCollection.mailAddress))
Note that we can use the table.column name syntax to access a single column of a multi column table.
Add these formulas to an onselect property of a button, run your app, click the button, then view your collections to see if the results are as you expect.
When you have this all working change the MyEmailCollection to your datatable. Repeat the above checks. When that is working replace your search term to the input of your textbox.
When that is all working then take your filter formula and set it to the items property of your gallery.
Using the approach described above all should work fine, if there is an error you can see where it is straight away. i.e. with you filter, with your column or your text input.
Hope this helps,
Luke
Luke,
Thanks for the help. I followed your instructions and was able to get a little farther. The filter is only returning one result even though there should be two.
Here is what my code looks like:
;ClearCollect(collection1,TrimEnds(ShowColumns('[dbo].[vw_Emails]',"email_address")))
;ClearCollect(collection2,Filter(Office365Users.SearchUser({searchTerm:"Yang"}), Mail in collection1.email_address))
I would run the following and check the email addresses in each collection to make sure they are actually the same... it sounds like they might be different?
ClearCollect(collection1,TrimEnds(ShowColumns('[dbo].[vw_Emails]',"email_address")));
ClearCollect(collection2,Filter(Office365Users.SearchUser({searchTerm:"Yang"})).Mail);
ClearCollect(collection3,Filter(Office365Users.SearchUser({searchTerm:"Yang"}), Mail in collection1.email_address))
report back and we will see what we can do if it still doesnt work.
Thanks,
Luke
I had to tweak the second line to be the following:
ClearCollect(collection2,Filter(Office365Users.SearchUser({searchTerm:"Yang"})).Mail);
Here are the results:
Seems the "in" clause isn't working as expected.
Clarification...
collection2 might have more than 5 rows... PowerApps only shows five rows in the collections preview.
@sjlee I have tested the in clause and it worked fine for me. I suggest you look at the email addresses in the first 2 collections and make sure they are exactly the same letter for letter. You can view the contents of the collections by loading them into a table.
Thanks,
Luke
User | Count |
---|---|
254 | |
106 | |
95 | |
50 | |
39 |