Skip to main content

How to Use the Defaults Function in Power Apps

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

Defaults gives you a data source's default values as a record. Its main job is to tell Patch "create a new item" rather than "update this one".

Syntax​

Syntax
Defaults( DataSource )

Microsoft's reference: it "returns a record that contains the default values for the data source. If a column within the data source doesn't have a default value, that property isn't present." For a collection, it returns an empty record (Defaults function).

Prerequisites​

  • A data source in the app, such as a SharePoint list.

Example: Create an Item with Patch​

In the Career Development Plan app, the Send button creates a response the first time and updates it afterwards. Defaults is the "first time" part:

Inside btnSendRS → OnSelect
Patch(
CompetencyResponses,
If(IsBlank(locResponse), Defaults(CompetencyResponses), locResponse),
{ ... }
)

With Defaults(CompetencyResponses) selected in the formula bar, the preview strip shows it's a Record:

The expanded formula bar of btnSendRS with Defaults(CompetencyResponses) highlighted inside the Patch, and the preview strip reading Defaults(CompetencyResponses) with Data type Record

In preview, the first Send to manager created a new item in the list (How to Create or Update a SharePoint List Item with Patch).

Don't Rely on What's Inside​

In Studio, expanding the strip for Defaults(CompetencyResponses) showed We didn't find any data. A test formula reading Defaults(CompetencyResponses).Status.Value showed nothing either, although the list's Status column has Pending as its default in SharePoint.

So set every value your app depends on in the Patch itself. The example sets Status: {Value: StatusPending} explicitly, and the new item was saved as Pending.

Common Mistakes​

MistakeWhat happensDo this instead
Defaults(ListA) in a Patch to ListBNo item is createdMicrosoft: the two data sources must match
Relying on a column's defaultThe app's behavior depends on list settingsSet the value in the Patch
Using Defaults to updateA new item every timeUse the loaded record for updates

Troubleshooting​

SymptomLikely causeFix
Duplicates instead of updatesDefaults was used although an item existedCheck how the existing item is loaded
A required column error on createDefaults don't cover every required columnSet those columns in the change record

FAQ​

Can I prefill a form with Defaults?​

Yes, that's the other use Microsoft mentions: "to prepopulate a data entry form".

What does it return for a collection?​

An empty record, because collections have no defaults.

Conclusion​

Defaults(DataSource) is the base record that makes Patch create a new item. Treat its contents as unknown and set every value your app needs yourself.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.