Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Filter a datatable by user?

(0) ShareShare
ReportReport
Posted on by

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

  • Re: Filter a datatable by user?

    good point...thank you! 

  • Verified answer
    timl Profile Picture
    timl 34,377 on at
    Re: Filter a datatable by user?

    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.

    https://powerusers.microsoft.com/t5/General-Discussion/Delegation-not-working-as-documented-with-SQL-Server/m-p/239275#M70162

     

    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-UserProfile/td-p/44900

    Hope that's of some use to you.

  • 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)

     

  • timl Profile Picture
    timl 34,377 on at
    Re: Filter a datatable by user?

    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?

  • Re: Filter a datatable by user?

    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.

     

     

  • 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.

  • timl Profile Picture
    timl 34,377 on at
    Re: Filter a datatable by user?

    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.

  • 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?

     

  • timl Profile Picture
    timl 34,377 on at
    Re: Filter a datatable by user?

    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?

     

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,636

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,942

Leaderboard