Hi,
I connected my PowerApp to SQL Server and used a datatable to represent the table I have in SQL Server. This datatable/table has about 1,000 records. The first column is "name", which represents an employees' name.
Is it possible to filter this datatable to only show the current users' record? For instance, let's say Barry Manowhich launched the PowerApp and navigates to the screen with the datatable. Can I filter it so that it'll only show information related to Barry Manowhich?
So far, I used a Button and set the OnSelect = Set(_currentUser,User().FullName)
Then on my datatable, I set Items = Filter(Search('[dbo].[CV_V_CURR_EMP_BALANCES]'), name=_currentUser)
On the OnStart of the App, I put in Set(_currentUser,User().FullName)
I'm getting several errors, can anyone point why I'm getting these errors?
Thank you
good point...thank you!
Hi @Anonymous
Just for info, I would always recommend that you always store a value such as Office365Users.MyProfile().DisplayName in a variable, particularly if you want to use it with a function such as Filter.
The reason for this is that calling Office365Users inside a Filter will make queries non-delegable.
When PowerApps executes this type of query, it'll call Office365Users for each row that it returns. There is a 'rate limit' to calling Office365Users, and it's possible to exceed this limit under high load.
Hope that's of some use to you.
If you are not going to use the name variable many times, maybe it is better to add the name call on the filter function
Filter('[dbo].[CV_V_CURR_EMP_BALANCES]', name=Office365Users.MyProfile().DisplayName)
Hi @Anonymous
That's strange because what you've entered in the OnStart is valid syntax. Could there possibly be some other text or characters after your call to the Set function?
Hi @timl @Anonymous
I also wanted to mention, when I declare my _currentUser variable on the OnStart screen, I receive 2 errors: One under "Set" which says Expected Operator. We expect an opersator such as +,*, or & ...... no operator between them. The other error I receive is under the comma is unexpected characters. The formula contains 'ParenClose' where 'Comma' is expected and Characters are used in the formula in an unexpected way.
Check first if the name return from the User() has the same format as your column. Just put the formulas in the Text property of a label to see what returns.
In my organisation User().FullName returns "FirstName LastName", as an alternative I tried the following function: Office365Users.MyProfile().DisplayName in my case this one returns "LastName, FirstName" format. To use this last function you need to add the Office365 connection first.
Hi @Anonymous
User().FullName will return the name in the format "FirstName LastName". Unless the names in your data table match this format, this technique won't return the records that you expect.
Hi @timl
If I take out the Search function, the formula doesn't recognize the "name" column with the green outline.
When I inserted the formula you provided, the errors are gone but I receive a "we ddin't find any data to show at this time" message...
My initial thought is that the name column in my datatable is "Last Name, First Name". If I use the FullName function, does it list as "First Name, Last Name"?
Also, the name's in the datatable aren't exactly uniform. For example, I have an Plumlee, Marshall, G. and a different record has Lillard, Damian, Gerald. Could the formatting be the issue?
Hi @Anonymous
If you just apply Filter function in the Items property of your datatable, that should solve the problem.
Filter('[dbo].[CV_V_CURR_EMP_BALANCES]', name=_currentUser)
If not, can you post the errors that you're receiving?