Canvas Apps Expressions

Checking all items in a gallery for a specific value

Being active on the Power Apps Community has helped me come across some interesting scenarios that have been fun to solve! One of the most recent ones was to show (or hide) a button if the status of all the items in a gallery was equal to a given value e.g. open (or closed).

We are all used to referencing a gallery record with an expression like Gallery.Selected. But how do we reference all of them? There are many ways this can be accomplished. The one that I liked is based on the following logic:

  • Count the number of rows in the gallery for which the status is equal to open
  • Count the total number of rows in the gallery
  • If the two counts are equal, then set the visibility of the button to true, else false

Here are two galleries that we will use for this example (the Visible properties of both buttons is currently set to true)

Given our scenario, we would want Button 1 to be visible and Button 2 to be hidden.

Following the above outlined logic:

  • The count of rows in the gallery for which the status = open can be achieved by:
CountIf(Gallery1.AllItems, Status = "Open")
  • The total count of rows in the gallery can be achieved by:
CountRows(Gallery1.AllItems)
  • The Visible property of Button 1 needs to be set as:
If(CountIf(Gallery1.AllItems, Status = “Open”) = CountRows(Gallery1.AllItems), true, false)

The Visible property of Button 2 needs to be set as:

If(CountIf(Gallery2.AllItems, Status = “Open”) = CountRows(Gallery2.AllItems), true, false)

This will produce the desired result as shown below.

Have fun! Get addicted!

1 thought on “Checking all items in a gallery for a specific value”

Leave a Reply