web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Filter Gallery by Curr...
Power Apps
Answered

Filter Gallery by Current User

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi everyone, 

 

I'm trying to figure out how to filter the gallery so that the current user only sees its own data entries.

 

I've read many posts in the forum but none was able to provide me the correct solution.

 

This is what I did so far:

 

Set(VarUser; User())                                                                                                                     //declared in App

 

 

SortByColumns(                                                                                                                          //in Items in Gallery
      Search(
          Filter(
              [@MonthlyStatement];
             "EmployeeName" = VarUser.FullName);
             TextSearchBox1.Text;
             "crb06_MonthlyStatementID");
             "crb06_MonthlyStatementID";
             If(SortDescending1; Descending; Ascending)
)

 

This shows me no results at all even though the entry was successful.

 

This is the code without the filter and it's working properly:

SortByColumns(                                                                                                                          //in Items in Gallery
      Search(
              [@MonthlyStatement];
             TextSearchBox1.Text;
             "crb06_MonthlyStatementID");
             "crb06_MonthlyStatementID";
             If(SortDescending1; Descending; Ascending)
)

 

My table from which I'm retrieving the data looks like this:

 
MonthlyStatementIDEmployeeNameProject
0001Jack WickData security

 

 

The data is connected via Dataverse.

 

Any suggestion on what I could try?

 

Thanks!

 
Categories:
  • Verified answer
    Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @Anonymous 

    The solution that works for me is to create a global variable in the OnStart of the app.

    Set(useremail, User().Email) or Set(useremail;User().Email)

     Then the Items property of the gallery

     

    Filter(
     AddColumns(
     Orders, "UsersEmail",'Created By'.'Primary Email'
     ), UsersEmail = User().Email
    )

     

    This takes advantage of the metadata stored in a Dataverse table for the individual who created the record in the Orders table.  In your case:

    With(
     {wMonthlyStatement:Filter(
     AddColumns(
     [@MonthlyStatement];"UsersEmail";'Created By'.'Primary Email'
     ); UsersEmail = User().Email
     )
     };
    
     SortByColumns( 
     Search(
     wMonthlyStatement;
     TextSearchBox1.Text;
     "crb06_MonthlyStatementID" 
     );
     "crb06_MonthlyStatementID";
     If(SortDescending1; Descending; Ascending
     )
     )
    )
  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @Drrickryp 

     

    Thanks for the reply. This worked.

    Now I still have two questions though:

     

    - Why did we set the global variable usermail and then didn't use it in the filter but used?

    UsersEmail = User().Email

     
    - Now if I want to see the monthly statements that I created, Power Apps displays an error that the formula 

    BrowseGallery1.Selected

     is invalid because a "DataSource" compaitble values was expected. The name "BrowseGallery1" is correct.

    Do you know how I can fix this?

  • Verified answer
    Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    Yep,

    You need to use

    Lookup([@monthlystatement],ID= Browsegallery1.Selected.ID)

    Since you changed the datasource in the gallery it is no longer identical to the datasource in the form so you need a more specific item property that matches the datasource.

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @Anonymous 

    With regard to the usersEmail I pasted an older version but should have used the variable instead. The app will work much more efficiently if the variable userEmail replaces User().Email.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @Drrickryp   this worked perfectly as well.

    Nonetheless, if I actually try to use the global variable useremail then it doesn't work because it says that "This formula has side effects and cannot be evaluated" and it has created an internal error evaluating the expression.

    Set( UserEmail; User().Email )

     

    If I use the other version, i.e. no global variable and therefore

     

    UsersEmail = User().Email

     

    it works with no error.

     

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @Anonymous 

    Very odd.  I wonder if you Set(xxx;User().Email) in the OnStart and in the formula 

    AddColumns(
     [@MonthlyStatement];"UsersEmail";'Created By'.'Primary Email'
     ); UsersEmail = xxx

     whether that would make a difference.  Setting a global variable for a single value should reduce the communication between the device and the server every time the formula is used. 

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @Drrickryp 

    I did exactly that. I even tried to just create the variable 

    Set(varUser; User())

    and then in the gallery view use

    UsersEmail = varUser.Email

     but that didn't work either. 

    For now my app is not very complex, so I assume it's not going to be a big deal but it's still very strange.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 393 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 278 Most Valuable Professional

Last 30 days Overall leaderboard