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 / How can I use Countif ...
Power Apps
Answered

How can I use Countif dynamically referencing a Gallery

(0) ShareShare
ReportReport
Posted on by

Hi All,

So I have a text label with the syntax below to count the amount of employees reporting to a specific Manager. How can i make this dynamically so that when i click on an employee in the Gallery, that countif formula will update according to that employee? Is this possible?

 

"Approved Headcount" & " " & "|" & " " & CountIf('Org Chart', 'Reporting Manager'= "John Doe")

 

 

Categories:
  • TheRobRush Profile Picture
    11,128 Moderator on at

    set a contaxt variable, when you click on the employee

    UpdateContext({mgrVar:whateverpartoftheUser()thisis})

    then formula becomes

    "Approved Headcount" & " " & "|" & " " & CountIf('Org Chart', 'Reporting Manager'= mgrVar)
  • punksterz626 Profile Picture
    on at

    Sorry, newbie here. where and how do i set up the contact variable? 

  • TheRobRush Profile Picture
    11,128 Moderator on at

    "when i click on an employee in the Gallery" whatever you are doing there, set it's onselect to

    UpdateContext({mgrVar:whateverpartoftheUser()thisis})

     but change the whateverpartthisis section to thisitem.value you want to reference (assuming it's .displayname, but every org is different)

  • punksterz626 Profile Picture
    on at

    Does it matter if what i'm referencing is from a different screen?

     

    Ex. Screen1, click employee opens up Screen2 (this is where the countif formula will be at)

  • Verified answer
    TheRobRush Profile Picture
    11,128 Moderator on at

    yes, instead of updatecontext({item:value}) use Set(mgrVar, referenceinfo)

     

    Set makes a global variable, updatecontext is local to the screen

  • punksterz626 Profile Picture
    on at

    Screen1 - clicked on specific employee (john Doe) -Onselect property input Set(mgrVar, ThisItem.Employee) Employee is a column from a SP list where the name of the employee is housed at. 

     

    Screen2 - textlabel box with this syntax "Approved Headcount" & " " & "|" & " " & CountIf('Org Chart', 'Reporting Manager'= mgrVar) 

     

    its coming up as 0. What am I doing wrong here?

  • TheRobRush Profile Picture
    11,128 Moderator on at

    somewhere throw a label that is mgrVar, to make sure the variable passed like you expected it to. after that, put a gallery in and set it's items to Filter('Org Chart', 'Reporting Manager'= mgrVar) and see if it gives you items back. need to break down each step and find the failure point

  • punksterz626 Profile Picture
    on at

    I found where the error lies. I have a Nextarrow on the gallery that navigate to screen2. That is where i set the variable as suggested and it worked.

     

    Navigate(HomeScreen2) && Set(mgrVar, ThisItem.Employee)

  • TheRobRush Profile Picture
    11,128 Moderator on at

    Excellent, glad it is up and running

     

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 360 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 325

#3
Mohsin Ali Profile Picture

Mohsin Ali 232

Last 30 days Overall leaderboard