web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Set multiple variables...
Power Apps
Answered

Set multiple variables with Set function?

(0) ShareShare
ReportReport
Posted on by 33

So, I'm pretty sure I know the answer to this but I'm hoping someone can guide me in another way to do what I'm doing.  I have the below If statement (I actually have four of them that are similar but just set the variables to different values based on the condition):

 

If(
 And(
 varProductType = "Advanced",
 varCareType = "Plus"
 ),
 UpdateContext(
 {
 varDescription_3: Filter(
 Products,
 ProductDescription = ddoCare.SelectedText.Value & " for " & cboDescription_1.Selected.ProductDescription
 ),
 varDescription_4: Filter(
 Products,
 ProductDescription = ddoCare.SelectedText.Value & " for " & cboDescription_2.Selected.ProductDescription
 ),
 varDescription_5: Filter(
 Products,
 ProductDescription = ""
 ),
 varDescription_6: Filter(
 Products,
 ProductDescription = ""
 ),
 varDescription_7: Filter(
 Products,
 ProductDescription = ""
 )
 }
 )
)

 

I have come to the point where I need to make the variables Global.  However, from everything I have read, I can use the Set function to set multiple variables at once like you can with UpdateContext.  I really don't want to have to create an If statement for every single variable because I have three more If statements like the one above so I would end up with 20 If statements.  I could do but it just seems like there would be a better way.

 

Any thoughts?

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

    Hi @Tarterman ,

    Actually not much more code for global

    If(
     varProductType = "Advanced" && varCareType = "Plus",
     Set(
     varDescription_3,
     Filter(
     Products,
     ProductDescription = ddoCare.SelectedText.Value & 
     " for " & cboDescription_1.Selected.ProductDescription
     )
     );
     Set(
     varDescription_4,
     Filter(
     Products,
     ProductDescription = ddoCare.SelectedText.Value & 
     " for " & cboDescription_2.Selected.ProductDescription
     )
     );
     Set(
     varDescription_5,
     Filter(
     Products,
     ProductDescription = ""
     ),
     );
     Set(
     varDescription_6,
     Filter(
     Products,
     ProductDescription = ""
     );
     Set(
     varDescription_7,
     Filter(
     Products,
     ProductDescription = ""
     )
     )
    )

     

    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.

  • Tarterman Profile Picture
    33 on at

    Thanks @WarrenBelz.  That was way easier than I thought.  For some reason, I thought that a semicolon marked the end of a statement (which it does) but I didn't realize you could do that in the middle of another statement.  Thanks again for the help.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard