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 / Updating a variable
Power Apps
Answered

Updating a variable

(0) ShareShare
ReportReport
Posted on by 62

Hi

 

In my app I have a drop down with a list of values 1-20. the drop down's on change is Set(y,<nameOfDropDown>.SelectedText), which is fine. The thing is that when I go to that screen, y is not yet set, so y has a 0 value, which is not good for the rest of what's going on in the screen.

I tried setting the default value of the box to 1, but I get why that doesn't work, which leads to my issue. I tried to set the screens OnVisible to be Set(y, 1) kinda like you would do with a variable in any other programing language. The dropdown box declaration y was however not so happy with that, causing a whole string of errors with multiple declarations...

My question then is. how do I make a variable with an initial value, and then change it to later to be what you select in the dropdown box?

btw, I have tried using UpdateContext too to keep it local, which would be best practice, buut, it didn't change anything.

Categories:
I have the same question (0)
  • Verified answer
    eka24 Profile Picture
    20,925 on at

    With Set(y,<nameOfDropDown>.SelectedText), Can you give the Items formula of the Dropdown. That will determine what will go into the variable.

    However, try OnVisible of the screen: Set(y,nameOfDropDown.Selected.Value

    ------------

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

     

  • Mats_1997 Profile Picture
    62 on at

    @eka24 

    That solves the initializing problem, but I could just as well have used Set(y, 1), it does not make the y value change when you change the value of the drop down 😕

    I'd like something similar to
    screen OnVisible: Set(y, 1)
    dropdown Onchange: Update(y, dropdown.SelectedText)

  • eka24 Profile Picture
    20,925 on at

    Please show the items of the dropdown to help solve the issue

    ------------

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

  • Mats_1997 Profile Picture
    62 on at

     12345.PNG
    Like I said in my OP, I filed it with an array of int 1-20 ^^. The issue is that, yes, I can initialize a value in the screens OnVisible function like this: Set(y, dropdown.Selected.value), which will initially set it to 1 as is desired, but, it won't dynamically change the value in the dropdown. I also can't use go to the dropdowns onChange function and write Set(y, dropdown.selected.value) to dynamically uppdate y...

    So I wonder how can I initialize a varable AND dynamically uppdate it as changes are made to the dropdown 

  • eka24 Profile Picture
    20,925 on at

    You can set a variable OnChange of the Dropdown:

    Set(YY,Dropdown2.SelectedText.Value)
    ------------

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.
  • Mats_1997 Profile Picture
    62 on at

    @eka24 

     

    I'm sorry, I think I'm not explaining properly
    I have a variable y, that needs to start as 1, but change to be something else when I change the drop down. the variable value needs to change from when it is initialized

  • Verified answer
    Mats_1997 Profile Picture
    62 on at

    I have no idea why, suddenly it just worked, with the screens onSelect being Set(y,1) and the dropDown Onchange being Set(y, MyDropDown.Selected.Value) almost as @eka24  suggested, no idea why it suddenly worked, because it didn't work the first time I tried it

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!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 899

#2
Valantis Profile Picture

Valantis 571

#3
11manish Profile Picture

11manish 499

Last 30 days Overall leaderboard