Skip to main content

How to Save a Toggle to a SharePoint Yes/No Column in Power Apps

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

A SharePoint Yes/No column is a true-or-false value in Power Apps, and a toggle is a true-or-false control. Show the saved value with the toggle's Default, and save it with Patch and the toggle's Checked.

Syntax​

Syntax
// ToggleName → Default: the saved value, or a starting value for a new item
If(IsBlank(Item), NewItemValue, Item.YesNoColumn)

// In the Patch that saves the item
Patch(DataSource, BaseRecord, {YesNoColumn: ToggleName.Checked})
PartWhat it is
ItemThe item being edited, such as a variable that holds it. Blank for a new item.
NewItemValuetrue or false: how the toggle starts for a new item.
YesNoColumnThe Yes/No column.
DataSource, BaseRecordThe list, and Defaults(DataSource) for a new item or the item to change (How to Create or Update a SharePoint List Item with Patch in Power Apps).
ToggleName.Checkedtrue while the toggle is on, false while it's off.

The example below is a Departments list whose IsActive column says whether a department is in use, with an Active switch on the form that adds and edits departments.

Prerequisites​

How Power Apps Sees a Yes/No Column​

Microsoft's SharePoint connector page maps Yes/No (checkbox) to Power Apps' Boolean type: true for Yes and false for No. A toggle's Checked is a Boolean too, so the two fit together without converting anything.

Step 1: Show the Saved Value​

Set the toggle's Default to the column of the item being edited, with a starting value for a new item:

tglActiveED → Default
If(IsBlank(locDepartment), true, locDepartment.IsActive)

A new department starts active. Editing Day Surgery, the preview strip showed its saved value, true:

The formula bar with the Default property of tglActiveED set to If(IsBlank(locDepartment), true, locDepartment.IsActive), the preview strip reading true with Data type boolean, and the Edit department form with the Active toggle on

A toggle keeps what the user set until it's reset, so reset it when the screen opens: then each item shows its own value (How to Reset a Control to Its Default Value in Power Apps with Reset).

Part of the screen's OnVisible
Reset(tglActiveED)

Step 2: Save It with Patch​

Put the column in the Patch record with the toggle's Checked. The example's Save button adds or updates the department, with the toggle's value as IsActive:

btnSaveED → OnSelect
UpdateContext({locIsSaving: true});
IfError(
Patch(
Departments,
If(IsBlank(locDepartment), Defaults(Departments), locDepartment),
{
Department: Trim(txtNameED.Text),
Approvers: cmbApproversED.SelectedItems,
IsActive: tglActiveED.Checked
}
),
UpdateContext({locIsSaving: false});
Notify("The department wasn't saved. " & FirstError.Message, NotificationType.Error),
UpdateContext({locIsSaving: false});
Notify(If(IsBlank(locDepartment), "The department was added.", "Your changes were saved."), NotificationType.Success);
Back()
)

The expanded formula bar with the OnSelect of btnSaveED, a Patch of Departments that sets Department, Approvers and IsActive: tglActiveED.Checked, with the referenced controls highlighted, above the Edit department form

Step 3: Check What Was Saved​

I added Day Surgery with the toggle off. The app's list of departments showed it as Inactive:

The Departments screen with The department was added. and Day Surgery with an Inactive badge above Emergency Department, Finance and Radiology, each Active

Then I edited it and switched the toggle on. In SharePoint, the IsActive column shows a tick for Yes, and Day Surgery had one, like the others:

The Departments list in SharePoint with the columns Department, Approvers and IsActive, and four items, Emergency Department, Radiology, Finance and Day Surgery, each with a tick under IsActive

Common Mistakes​

MistakeWhat happensDo this instead
Saving tglActiveED.DefaultThe starting value is saved, not what the user setSave .Checked
Patching the text "Yes" or "No"The column takes a Booleantrue, false or .Checked
Not resetting the toggle when the screen opensThe next item shows the last item's valueReset(tglActiveED) in OnVisible
No starting value for new itemsDefault reads a column of a blank recordGive new items a value: If(IsBlank(record), true, record.Column)

Troubleshooting​

SymptomLikely causeFix
The toggle always starts off when editingDefault doesn't read the itemlocDepartment.IsActive in Default
SharePoint shows the old valueThe Patch failedRead the message from FirstError.Message

FAQ​

Why does SharePoint show a tick instead of Yes?​

That's how the modern list view shows Yes in a Yes/No column. The value behind it is still Yes, and Power Apps reads it as true.

Can I filter on the column?​

Yes. Filter(Departments, IsActive = true) runs in SharePoint (Fixed: Delegation Warning. The "Filter" Part of This Formula Might Not Work Correctly on Large Data Sets).

Conclusion​

Set the toggle's Default to the item's Yes/No column (or true for a new item), reset it when the screen opens, and save .Checked in the Patch record.

Additional Resources​