
Hello Folks, In this #PowerGuideTip, I am going to share a Tip to set/reset value in Choice (earlier name: Option Set) and Lookup field of Microsoft Dataverse in Power Apps.
Requirements
I have came across numerous business requirements and have also seen folks asking in community about setting/resetting value in choice (dropdown/optionset) and lookup field on button click. This article helps you fulfill following business requirements in Power Apps:
- Set value in Choice (Option Set) field of Microsoft Dataverse on-demand in Edit form.
- Set value in Lookup field on-demand in Edit form.
- Autopopulate value in Choice field in Edit form.
- Autopopulate value in Lookup field in Edit form.
- Reset/Clear Choice and Lookup fields in Edit form.
Note: Power Apps use Combo Box control to render Choice and Lookup type fields in Power Apps Edit form.
Prerequisite
I already have a Power Apps Canvas app, where I have added Edit Form of Account table (Microsoft Dataverse). And the form has following controls:

Solution
For Lookup:
In order to set/reset the value in lookup field, I have used a global variable called ‘gvar_primaryContact’, that will hold the value I want to set on click of ‘Set Lookup’ button. Since it’s a lookup field, therefore you need to retrieve the record first from dataverse using Lookup function.
And finally, you need to set that global variable on ‘defaultselecteditem‘ property of the combo box.
Step 1: PowerFx expression onSelect property of ‘Set Lookup’ button.

Step 2: PowerFx expression onSelect property of ‘Reset Lookup’ button.

Step 3: PowerFx expression on DefaultSelectedItems property of ‘Combo Box’ control.

For Choices (Option Set):
In order to set/reset the value in Choice (Option Set) field, I have used a global variable called ‘gvar_businessType’, that will hold the value I want to set on click of ‘Set Dropdown’ button. Since it’s a Choice field, therefore you need to first retrieve its option value from dataverse using Lookup function.
Step 1: PowerFx expression onSelect property of ‘Set Dropdown’ button.

Step 2: PowerFx expression onSelect property of ‘Reset Dropdown’ button.

Step 3: PowerFx expression on DefaultSelectedItemsSelect property of ‘Set Dropdown’ button.

Important Tip: In this example, I have set/reset value on button click. If you want to autopopulate the value as soon as form loads, you can use the PowerFx expression (which i have written on onSelect property of the button) directly on DefaultSelectedItems property of the Combo Box. (See below)


Hope you find this #PowerGuideTip helpful. Stay tuned for further useful tips.