How to set default value in Power Apps data card?

In this Power Apps tutorial, we will discuss how to set a default Data Card value in Power Apps.

Recently, I was working with a requirement where I needed to set a default value in the Power Apps DataCard value. Also, we will discuss below topics such as:

  • How to set the Default value for the new records only?
  • How to set a default value on the Power Apps people data card?
  • How to set a default value in the Power Apps dropdown data card?
  • How to set a default value based on another field value?

To achieve this requirement, we will follow the below instructions.

Set default value for new records only in Power Apps Datacard

This section will show you how to set a default value for new records only. That is, when the user opens a new Power Apps form, the form will show a default value. Later, the user can change the default value and insert their own.

Requirement:

When the user opens a new Power Apps form, it will show a default value on the Address DataCard i.e., NY 1003, NewYork City, US. Users can use that default value or he/she can edit that DataCrad value.

Set default Power Apps datacard value in Power Apps
Set default Power Apps datacard value in Power Apps

Here, we have a SharePoint list named Employees having some different types of columns such as:

  • Employee Name: People Picker
  • Address: Multiline Column
  • Contact: Number
  • Join Date: Date & Time column
  • Department: Choices (i.e., IT, Finance, HR, Manager)
Set Power Apps Data Card default value for the new records only
Set Power Apps Data Card default value for the new records only

To fulfill the requirement, now we will create an edit form within the Power Apps. To create an edit form within the Power Apps, the following steps are:

  • On the Power Apps Canvas app, add the SharePoint list.
  • On the screen, click on the Insert > Edit form.
  • Connect the edit form to the SharePoint list (Employees). We can see that the edit form will retrieve and display all the SharePoint columns as shown below:
powerapps data card default value
powerapps data card default value
  • To set the default value within the ‘Address DataCard’, insert the below expression on the Address TextInput’s Default property.
Default = If(EmployeeDetailsForm.Mode = FormMode.New, "NY 1003, NewYork City, US", Parent.Default)

where,

  • EmployeeDetailsForm is the name of the Power Apps edit form.
  • NY 1003, NewYork City, US” is the name of the default value.
Set a default datacard value in Power Apps
Set a default datacard value in Power Apps
  • Next, set the form’s Default mode as New.
Set Power Apps default data card value
Set Power Apps default data card value

Because we set the form mode to new, the DataCard displays the default value. Similarly, the default value will be displayed each time the user opens the new form.

See also  Power Automate Get Data from Excel on SharePoint

This is how to set a default value within the Power Apps Data Card.

Read How to copy Power Apps Data Card value to another

Set a default value on the PowerApps people data card

In this section, we will see how to set a default value within the Power Apps people Datacard.

Requirement:

When the user opens a Power Apps form, it should display the current login user’s display name on the Employee Name’s DataCard.

Set default value in Power Apps People datacard
Set default value in Power Apps People datacard

To fulfill this requirement, we are going to use the above Power Apps edit form and the following steps are:

  • On the Power Apps, add a connector i.e., Office365Users.
  • Select the Employee Name field, and insert the below expression on the field’s Items property.
Items = Office365Users.SearchUser()

where Office365Users indicates the connector that we have used and SearchUser() indicated to the list of all users that displays within the employee’s dropdown.

Set a default value on the PowerApps people data card
Set a default value on the PowerApps people data card
  • Insert the below expression on the DefaultSelectedItems property of the Employee Name’s Dropdown control.
DefaultSelectedItems = Office365Users.MyProfile()

where Office365Users indicates the connector that we have used and MyProfile() indicated the current login user.

Set default value on the PowerApps people data card
Set the default value on the PowerApps people data card

That’s all! When the user opens the edit form, the current login user’s name is displayed as the default value in the Employee’s name field.

Set a default value on the PowerApps people datacard
Set a default value on the PowerApps people datacard

This is how to set a default value on the Power Apps People DataCard.

Read How to change Power Apps DataCard to dropdown

Set a default value in PowerApps dropdown data card

In this section, we will see how to set a default value in the Power Apps drop-down DataCard.

Requirement:

When the user opens the edit form, a default value will be visible in the dropdown control(Department as IT). Users can use that default value or he/she can select another value from the drop-down control.

Set a default value in the PowerApps dropdown data card
Set a default value in the PowerApps dropdown data card

To fulfill this requirement, we are going to use the above example of the Power Apps edit form, and the following steps are:

  • On the Power Apps edit form, select the Department Data Card.
  • Insert the below default value in the DefaultSelectedItems property of the Department DataCard.
DefaultSelectedItems = ["IT"]

As per the requirement, here we have set the default selected value as IT.

Power Apps set defaultvalue in Dropdown datacard
Power Apps set default value in Dropdown datacard

That’s all! Let’s save and close the app. From now onwards, when the user opens this form, it will display “IT” as the default value.

See also  Power Apps Radio Button

This is how to set the default value in the Power Apps Drop-Down datacard.

Read How to Update DataCard Value in Power Apps

Set a default datacard value based on another field value in Power Apps

In this section, we will see how to set a default value in Power Apps DataCard based on another field value.

Requirement:

When the user selects the Order Date, the Target Shipping Date will automatically shift to 5 days after the Order Date, unless a ‘Target Shipping Date’ is specified.

Set default value in Power Apps DataCard based on another field
Set default value in Power Apps DataCard based on another field

Here, we have a SharePoint list named Orders List having some different types of columns such as:

  • Title: Single line column
  • Order Date: Date & Time column
  • Order Qty: Number
  • Company: Choice (Dell, Apple, HP, Microsoft, Lenovo, etc)
  • Target Shipped Date: Date & Time column
  • Price: Currency
Set Power Apps default DataCrad value based on other field
Set Power Apps default DataCrad value based on other field

On the Power Apps, we will build an edit form by using the above SharePoint list (Orders List). To build this, the following steps are:

  • On the Power Apps, build a blank canvas app.
  • On the canvas app screen, add an edit form.
  • Connect that blank edit form with the SharePoint list (Orders List) as data source.
  • Now we can find all the fields on the edit fields retrieved from the SharePoint list.
Set PowerApps default DataCrad value based on other field
Set PowerApps default DataCrad value based on other field

To meet this requirement, we set the default value of the ‘Target Shipped Date‘ to the ‘Order Date’ plus 5 days, based on the value of a Boolean variable. When the user changes the ‘Order Date,’ we set this variable to true if the ‘Targer Shipped Date’ field is currently empty. For this, we will initialize a variable on the screen’s OnVisible property.

OnVisible = UpdateContext({VarShippedDate:false})

Where, VarShippedDate is the name of the context variable name and false indicates the boolean value of the variable.

Set default value based on the other Power Apps Data Card field
Set default value based on the other Power Apps Data Card field
  • Insert the below expression on the Target Shipped Date’s DefaultDate property.
DefaultDate = If(VarShippedDate, 
   DateAdd(DataCardValue10.SelectedDate, 5, Days), 
   Parent.Default
)

Where, DataCardValue10 is the name of the Date field name of the Order Date.

Set a default datacard value based on another field value in PowerApps
Set a default datacard value based on another field value in PowerApps
  • Next, insert the below expression on the OnChange property of the Order Date field/DataCard.
OnChange = If(IsBlank(DataCardValue14), 
   UpdateContext({VarShippedDate:true});
   Reset(DataCardValue14)
)

Where DataCardValue14 is the field name of the Target Shipped Date.

Set default datacard value based on another field value in PowerApps
Set default datacard value based on another field value in PowerApps
  • To save the inserted data to the SharePoint list, add a button control to the Power Apps edit form and insert the below expression on the button’s OnSelect property.
OnSelect = SubmitForm(ProductOrderDetailsForm)

where the ProductOrderDetailsForm is the name of the Power Apps edit form.

Set a default datacard value based on another Power Apps field value
Set a default datacard value based on another Power Apps field value

Note: To refresh the value of the ‘Target Shipped Date‘ control, we use the Reset(). If this call is not made, the display value of the ‘Target Shipped Date’ control will not immediately update following a change to the ‘Order Date’ value.

See also  How to Save Email Attachment to SharePoint using Power Automate?

That’s it! Let’s Preview the app. We can see that while we select the Order Date, the Target Shipped Date will update automatically.

Set default value based on another data card field value in Power Apps
Set default value based on another data card field value in Power Apps

Similarly, when we click on the button, the data get saved on the SharePoint list as well. This is how to set default value based on another data card field value in Power Apps.

Conclusion

From this Power Apps Tutorial, we learned how to set default value in Power Apps based on different scenarios. Such as:

  • Set Default value for the new records only
  • Set a default value on the PowerApps people data card
  • Set a default value in the PowerApps dropdown data card
  • Set a default datacard value based on another field value in Power Apps

You may like the following Power Apps tutorials:

  • I have an existing powerapps connected to sharepoint list, I would like add a default value in a field “Reference Number” as “ICS-ID” where ID is the sharepoint list unique item which us automatically generated by sharepoint list, I could not find this ID field in powerapps to use as per your 4th last lesson in the above instructions. Can you please help me how to do it. Thanks-Gopi

  • >