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 not produ...
Power Apps
Answered

If Statement not producing expected results

(0) ShareShare
ReportReport
Posted on by 30

I have a simple powerapp. The first screen the user chooses one of two options and the result is put in global variable named varoption and transferred to a second screen. On the second screen, the Visible property is set on two data table controls based on the global variable with the following code:

 

UpdateContext(locdt1Visible:false);

UpdateContext(locdt2Visible:false);

If (varoption = "test1", UpdateContext({locdt1Visible:true});

If (varoption = "test2", UpdateContext({locdt2Visible:true})

 

The first two lines are there to make sure Visible is set before the selection. locdt1 and 2 are local variables and hare in the Visible of each respective control.

I have tried to code this as a Select statement but that did not help.

 

Categories:
I have the same question (0)
  • BrianS Profile Picture
    2,407 Super User 2024 Season 1 on at

    Can't you just use the global variable everywhere you need it? In the one Gallery's Visible property just put

    varoption = "test1"

    and in the other

    varoption = "test2"

    They will evaluate as true or false and the Gallery will show or not. Since the variable is set before the page becomes visible yo should not need to worry that it will show

  • hcharris Profile Picture
    30 on at

    I put the following statement in the Visible property of each of the controls:

     

    If (varOption = "test1", true, false)

     

    a similar statement was added for the second control. Everything in OnVisible for the screen was removed.

     

    I'm so new to this I'm not even sure I'm testing correctly. Right now I save after making changes and then run it. Both controls begin with Visible = false. But when I test. neither control is showing.

     

    I know what is being passed in the var because it is displayed in a message at the top of the screen.

     

    I'll keep trying to figure it out.

  • Verified answer
    BrianS Profile Picture
    2,407 Super User 2024 Season 1 on at

    Good idea to put the value of the variable on the screens for testing!

    You do not really need the If statement in the Visible property, it is looking for a Boolean, so anything that evaluates to true or false will do, so all you really need is 

    varOption = "test1"

    and it will work.

    If you highlight that statement does it show the correct answer? For testing can you copy the control for varOption to the second page? It should change the visibility on the fly. If you only have the 2 states yo could also change that variable to Boolean and then just list the variable in the Visible property of the Galleries - one would just have the variable the other would be 

    !varOption

     

  • hcharris Profile Picture
    30 on at

    That worked like a champ. You have shown kindness to an old coder who gave it up when C++ came out. I actually met Grace Hopper.

  • BrianS Profile Picture
    2,407 Super User 2024 Season 1 on at

    Us old guys have to stick together - I pretty much gave up database work after Foxpro died an ugly death!

    Got sucked back in with this product

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 379 Most Valuable Professional

#2
11manish Profile Picture

11manish 203 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard