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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Setting a variable wit...
Power Apps
Unanswered

Setting a variable with a value from a Sharepoint List then filter a gallery with it

(0) ShareShare
ReportReport
Posted on by 125

Hi all,

 

I thought this should be simple but I am struggling with the formula.

 

I am trying to simply set a variable varUserDepartment with the staff members department as stored on a sharepoint list

 

i.e. Sharepoint List "Staff List" is as follows

 

Department (choice field) Name (people field)

Accounts     Joe Bloggs

IT                Janet Doe

 

In PowerApps - when Janet Doe logs in I want to set the varUserDeprtment to equal 'IT' (based on a "Staff List") and then set a Gallery (based on a "Projects List") to only show Projects where the department matches varUserDepartment

 

I am setting the value for the variable varUserDepartment on my onStart and getting this correctly populated (tested with just adding a text label on my screen).

 

This is the Items property of my gallery - I can't get to work (I have some filter options - these are working correctly on their own)

 

SortByColumns(
Filter(
Search('Staff Projects',txtSearchName_2.Text, "Full_x0020_Name"),
('Review Status' = cmbSearchStatus_2.Selected.Value || IsBlank(cmbSearchStatus_2.Selected.Value)) &&
('Department' = varUserDepartment || IsBlank(varUserDepartment))),
"Review_x0020_Status", SortOrder.Ascending);

 

Can anyone assist me please 🙂

 

Thanks so much

 

 

 

 

 

Categories:
I have the same question (0)
  • JeffreyGonzalez Profile Picture
    61 on at

    If I am understanding correctly what you are trying to accomplish, you may want to look into the Office365Users.UserProfilev2() Power-fx function in conjunction with the User() function a simple way to do this would be to do the following in the onstart property of your app:

    Set(varUserDepartment, Office365Users.UserProfileV2(User().Email).department)

     

  • glitter1234567 Profile Picture
    125 on at

    Hi Jeffrey,

     

    Many thanks for your reply - my set varUserDepartment is working fine on the onstart.  It's the filter on the gallery that I can't get right 🙂

     

    Thanks

    Karen

  • JeffreyGonzalez Profile Picture
    61 on at

    Once you get the department set, you will want to do the following to get the data into a gallery:

    ClearCollect(colGalleryItems, Filter('SharePoint List Name', Department = varUserDepartment))

    Try plugging the collection into your formula in place of the SharePoint list data source. 

  • JeffreyGonzalez Profile Picture
    61 on at

    I am going to set this up as similar as I can on my end and recreate. In the meantime, let me know if collecting the data into a collection and filtering/sorting that helps. 

    Are there any errors that pop up when you try to filter like that?

     

  • glitter1234567 Profile Picture
    125 on at

    So is colGalleryItems a collection - where do I set that?  Sorry I haven't used collections before - I am new to PowerApps and learning on the job!

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard