cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper III
Helper III

Filter a datatable by user?

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

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User
Super User

Re: Filter a datatable by user?

Hi @KOM_4410 

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.

https://powerusers.microsoft.com/t5/General-Discussion/Delegation-not-working-as-documented-with-SQL...

 

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.

 

https://powerusers.microsoft.com/t5/General-Discussion/rate-limit-is-exceeded-using-Office365Users-U...

Hope that's of some use to you.

View solution in original post

9 REPLIES 9
Highlighted
Super User
Super User

Re: Filter a datatable by user?

Hi @akim91 

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?

 

 

 

Highlighted
Helper III
Helper III

Re: Filter a datatable by user?

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?

 

Highlighted
Super User
Super User

Re: Filter a datatable by user?

Hi @akim91 

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.

Highlighted
Resolver II
Resolver II

Re: Filter a datatable by user?

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.

Highlighted
Helper III
Helper III

Re: Filter a datatable by user?

Hi @timl @KOM_4410 

 

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.

 

 

Highlighted
Super User
Super User

Re: Filter a datatable by user?

Hi @akim91 

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?

Highlighted
Resolver II
Resolver II

Re: Filter a datatable by user?

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)

 

Highlighted
Super User
Super User

Re: Filter a datatable by user?

Hi @KOM_4410 

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.

https://powerusers.microsoft.com/t5/General-Discussion/Delegation-not-working-as-documented-with-SQL...

 

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.

 

https://powerusers.microsoft.com/t5/General-Discussion/rate-limit-is-exceeded-using-Office365Users-U...

Hope that's of some use to you.

View solution in original post

Highlighted
Resolver II
Resolver II

Re: Filter a datatable by user?

good point...thank you! 

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,373)