Set

How to Use the Power Fx Set  Function in Power Apps

The Set function in Power Fx is a powerful tool that enables users to set values for various controls within their applications. In this article, we will explore the different aspects of the Set function and how to use it effectively in Power Apps.

What is the Set Function in Power Fx?

The Set function in Power Fx allows users to set a value for a control within their Power Apps. This function is useful when creating custom applications that require data manipulation or transformation. For instance, the Set function can be used to update a particular field with a certain value, or it can be used to set the value of a control based on a certain condition.

How to Use the Set Function in Power Fx

To use the Set function in Power Fx, you need to follow the steps below:

Step 1: Identify the Control you want to Set a Value for

The first step in using the Set function is to identify the control you want to set a value for. This could be a field in a table, a text box, a label, or any other control within your Power App.

Step 2: Determine the Value you want to Set

Once you have identified the control you want to set a value for, the next step is to determine the value you want to set. This could be a static value, a formula, or a value from another control within your Power App.

Step 3: Use the Set Function

Once you have identified the control and value you want to set, the next step is to use the Set function. The basic syntax for the Set function is as follows:


Set(ControlName, Value)


In the above syntax, ControlName is the name of the control you want to set a value for, and Value is the value you want to set.

For instance, if you want to set the value of a text box named "txtName" to "John Doe", you would use the following formula:


Set(txtName, “John Doe”)


Alternatively, you can use a formula to set the value of a control. For instance, if you want to set the value of a text box named "txtAge" to the value of another control named "txtDOB", you would use the following formula:


Set(txtAge, Text(DateDiff(txtDOB.SelectedDate, Today(), Days)))


In the above formula, the DateDiff function is used to calculate the age based on the date of birth stored in the txtDOB control. The Text function is used to convert the result to text format.

Step 4: Use the Set Function with Conditions

The Set function can also be used with conditions to set the value of a control based on a certain condition. For instance, if you want to set the value of a text box named "txtStatus" to "Active" if a checkbox named "chkActive" is checked, and to "Inactive" otherwise, you would use the following formula:


If(chkActive.Value = true, Set(txtStatus, “Active”), Set(txtStatus, “Inactive”))


In the above formula, the If function is used to check if the chkActive control is checked. If it is, the value of the txtStatus control is set to "Active". Otherwise, it is set to "Inactive".

The Set function in Power Fx is a powerful tool that enables users to set values for controls within their Power Apps. By following the steps outlined in this article, you can use the Set function effectively to create custom applications that cater to your business needs.

Power Apps Training Courses by G Com Solutions (0800 998 9248)