cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Champ14
Helper I
Helper I

How to filter datatable based on who's user are logged in

Hi Experts,

I am trying to create a screen where there's a datatable connected to a SharePoint List, In this SharePoint List, there's a column that lists who created the entries, I want to Filter this Datatable to show only the entries of the current user logged in in the system, also the user can add another filter either to show only pending for approval, All approve, or show all records under his name. The SharePoint list has another column that records the status.

 

Logs_Request.PNG

17 REPLIES 17

Basically you need to create the collection as described above and use the name of the collection as 'items' of the gallery (example below uses the Email as a unique identifier): 

ClearCollect(colThisIsTheCollection,Filter(Datasource,Employee.Email = varUser.Email)

Hope that helps

 

If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

Hi @Champ14 

They both go on the list you want to filter, but in the end you would only use the bottom one as its a combination of the top one and more code.

The way i try to construct things, i try not to do multiple things in the first pass as its harder to troubleshoot.

This one allows you to work on the user filtering first, put this in and test it works

Filter( Datasource, 'Created By' = varUser.FullName)

 
once it does, expand the code to below and test the buttons and the filtering works.

If( 
status = "Pending", 
    Filter(Datasource, 'Created By' = varUser.FullName && 'Request Status' = "Pending", 
    status = "All Approved", Filter(Datasource, 'Created By' = varUser.FullName && 'Request Status' = "Approved"), 
    Filter(Datasource, 'Created By' = varUser.FullName)
    )
)



Hi All

 

I have tried to use the variable variable 

 

Set(varUser, User().FullName)

Set(varUser2, Office365Users.MyProfileV2().displayName)

 

but nothing was shown when I use it on a label, it just shows as blank for both variables

VarEmp.JPG

 

But when I use it directly to a label

User().FullName or Office365Users.MyProfileV2().displayName

 

The name are properly appearing, and it is exactly the same as the name appearing in the created by column.

JR-BejeweledOne
Super User
Super User

I use it all the time without any issues.  where are you setting the variable?   If varUser is blank, then it's not set



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

As I wrote before, you need to set the variable to User() (best without any .extension).

Then the variable will be of the same type as the User() itself. This means if you use it as the 'text' input of i.e. a Label field, you need to refer to the appropriate 'part' (i.e. varUser.FullName or varUser.Email) then it will work.

 

If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

Thanks @JR-BejeweledOne 

For some reason it works after I close and re open the application, I have now set the filtering in the Datatable, but its shows as blank.


 

Thanks @ArminSimon ,

Tried it for both and var is now working, it is now pulling out the correct name but filtering doesnt work as per below. No results come out.

norec.JPG

ArminSimon
Advocate I
Advocate I

you need to point to FullName of 'created by' as well ('Created By'.FullName).
Since in your command, you compare a record with a text.

Good video to explain this is created by @ShaneYoung 
https://www.youtube.com/watch?v=d1xR-YZifxo&ab_channel=ShaneYoung

 

If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

 

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,292)