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 / Clear syntax in a prop...
Power Apps
Answered

Clear syntax in a property

(0) ShareShare
ReportReport
Posted on by 104

Hello everyone,

 

Do you know a way to have a clearer syntax in the property. For example, below the code I would like write in a text proporty for a Label.

var myVar2 = Label2.Text
var myVar3 = Label3.Text
var myVar = ""
If (condition1, myVar = myVar2, myVar = myVar3)
return myVar

 

Okay... this example is really simple. But in my case, I can use a lot other widgets. So, to have not a very veyr very long IF, I would like define local variables in the property.

What do you think about this ?

 

Thank in advance and Have a nice weekend.

 

 

Charlie.

 

Categories:
I have the same question (0)
  • Nogueira1306 Profile Picture
    7,390 Super User 2024 Season 1 on at

    You can use UpdateContext and Set for vars

     

    https://docs.microsoft.com/en-US/powerapps/maker/canvas-apps/functions/function-set

     

    https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-updatecontext

     

    If you need additional help please tag me in your reply and please like my reply.
    If my reply provided you with a solution, pleased mark it as a solution ✔️!

    Best regards,
    Gonçalo Nogueira

    Check my LinkedIn!

    Check my User Group (pt-PT)!

    Last Post on Community

    My website!

  • Verified answer
    CarlosFigueira Profile Picture
    Microsoft Employee on at

    You can use the With function to define "variables" within properties. For example, in your scenario, you could set the Text property of your label to something along the lines of

     

    With(
     { myVar2: Label2.Text, myVar3: Label3.Text },
     With(
     { myVar: If(condition1, myVar2, myVar3) },
     myVar))

     

    Notice that they are not really 'variables' as their values won't change, they are more like aliases to other expressions.

    Hope this helps!

     

  • Charlie Profile Picture
    104 on at

    Hi,

     

    Set() and UpdateContext are not availoable only in the "property" like onSelect, onChange, ... ?

  • Nogueira1306 Profile Picture
    7,390 Super User 2024 Season 1 on at

    You  can also use it on App OnStart or in a screen OnVisible

     

     

  • CarlosFigueira Profile Picture
    Microsoft Employee on at

    That's correct, functions that have side effects (Set, UpdateContext, Patch, Collect, ...) are only available in behavior properties. Data properties, such as the Text property of a label, can only access functions that don't have side effects

  • Charlie Profile Picture
    104 on at

    Hi,

    Yes, perfect. It's good for me :).

  • Charlie Profile Picture
    104 on at

    Okay so, I will also try this ;).

    Thank you so much. 

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 1,055

#2
Valantis Profile Picture

Valantis 666

#2
11manish Profile Picture

11manish 666

Last 30 days Overall leaderboard