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 / If statement for items...
Power Apps
Answered

If statement for items in the gallery doesn't work

(0) ShareShare
ReportReport
Posted on by

Hi, I have two datasets that have to be used for two kinds of the app users. Depends of what kind of users is currently using the app, I would like the items in the gallery to be dynamically changed. I would like to use an if statement for that (both datasets have the same columns, so it should not be a problem, Title is the same as Common Name and the app is reading that correctly):

 

plona95_2-1674643581493.png

 

Everything seems to be fine, but when I use If statement, all columns became not recognized:

 

plona95_0-1674643349430.png

 

When I use code 1:

plona95_0-1674643894163.png

 

 

Or code 2:

plona95_4-1674643687518.png

 

 

Separately, without using If, the values in the gallery are always recognized.

Could you please help me in finding any workaround so this can start working fine? I tried with switch and the error is the same:

plona95_5-1674643762596.png

 

Thank you!

 

Categories:
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    154,399 Most Valuable Professional on at

    Hi @plona95 ,

    Firstly, in my experience conditional Items do not "play  well" with Table controls such as drop-downs and Galleries. Try this first

    With(
     {
     wData:
     If(
     varSxxxx,
     AddColumns(
     Filter(
     COLSxxx,
     'Site Name' = BrowseGallery2.Selected.Result
     ),
     "SearchField",
     'Common Name'
     ),
     AddColumns(
     Filter(
     COLRotating,
     'Site name' = BrowseGallery2.Selected.Result
     ),
     "SearchField",
     Title
     )
     },
     Search(
     wData,
     TextSearchBoxl_2.Text,
     "SearchField"
     )
     )
    )

    Also please post all code in Text - this was OCR'd so watch spelling.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • plona95 Profile Picture
    on at

    Hi @WarrenBelz 

     

    Thank you for the message. I fixed the code and now it is the following:

    With(
    {
    wData:
    If(
    VarSxxx = true,
    AddColumns(
    Filter(
    COLSxxx,
    'Site name' = BrowseGallery2.Selected.Result
    ),
    "SearchField",
    'Common Name'
    ),
    AddColumns(
    Filter(
    COLRotating,
    'Site name' = BrowseGallery2.Selected.Result
    ),
    "SearchField",
    Title
    )
    ) },
    Search(
    wData,
    TextSearchBox1_2.Text,
    "SearchField"
    )
    )

     

    But the problem is - I can only retrieve 'SearchField' in the gallery. How to make the other columns of the table available?

  • WarrenBelz Profile Picture
    154,399 Most Valuable Professional on at

    @plona95 ,

    As I noted, conditional Items simply do not "play well" with these Table controls as they expect to have exactly the same table for all the possibilities (or they cannot present a consistent output). Are all the field names of both collections exactly the same ?

  • pal95 Profile Picture
    264 on at

    Hi Warren,

     

    Yes, they are both exactly the same

    Best regards,

  • WarrenBelz Profile Picture
    154,399 Most Valuable Professional on at

    @pal95 ,

    Then you are going to have to make a Collection using the same code and have that as the Items of the Gallery - I suggest wherever you set the varSxxx value

    With(
     {
     wData:
     AddColumns(
     Filter(
     COLSxxx,
     'Site Name' = BrowseGallery2.Selected.Result
     )
     ),
     wData2:
     AddColumns(
     Filter(
     COLRotating,
     'Site name' = BrowseGallery2.Selected.Result
     )
     )
     },
     ClearCollect(
     colData,
     If(
     varSxxxx,
     wData1,
     wData2
     )
     )
    )	

    Your Gallery Items

    Search(
     colData,
     TextSearchBoxl_2.Text,
     "SearchField"
    )

     I will be honest - I have largely given up trying to do this with Table controls - the possible options need to be exactly the same for the output.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

  • plona95 Profile Picture
    on at

    Thank you, I abandoned this way, I will use a different database or find another workaround

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Haque Profile Picture

Haque 94

#2
WarrenBelz Profile Picture

WarrenBelz 82 Most Valuable Professional

#3
Kalathiya Profile Picture

Kalathiya 38 Super User 2026 Season 1

Last 30 days Overall leaderboard