Skip to main content

How to Prevent Duplicate Items in a SharePoint List from Power Apps

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

To stop people from adding the same item twice, look for it before you save. If a matching item exists, show a message and don't save. On SharePoint, the lookup can run in the list itself, as long as it compares columns with =.

Prerequisites​

Step 1: Decide What Counts as the Same​

In the example, a competency belongs to a job title, and the same name may appear under different job titles. So a duplicate is an item with the same JobTitle and the same Competency name. The name is trimmed first, so extra spaces don't make a different name (How to Remove Extra Spaces with Trim).

Step 2: Look for It Before Saving​

Find the matching item with LookUp (How to Find a Record with LookUp), and keep it in a name with With (How to Use the With Function):

btnSaveCS → OnSelect (part)
With(
{
existing: LookUp(
RoleCompetencies,
JobTitle = locJobTitle && Competency = Trim(txtNameCS.Text)
)
},
...
)

Both conditions use = on text columns joined with &&, which SharePoint can run itself, so the check works at any list size (What Is Delegation in Power Apps?). JobTitle is indexed, as Microsoft recommends for columns you filter large lists by (How to Index a Column in a SharePoint List).

Step 3: Stop with a Message​

If existing is an active item, show an error and don't save:

btnSaveCS → OnSelect (part)
If(
existing.IsActive,
Notify(existing.Competency & " is already in the plan for " & locJobTitle & ".", NotificationType.Error),
Patch(...)
)

The message uses existing.Competency, the name as it's stored, rather than what was typed. In the test below, I typed leadership in lowercase while the list had Leadership. The lookup still found it, and the message showed the stored spelling:

The Add competency screen with leadership typed as the name and Advanced as the level, and a red banner at the top reading Leadership is already in the plan for Head of Sales.

Nothing was created. The list still had one Leadership for the job title.

Step 4: Decide What to Do with Removed Items​

The example never deletes competencies. Removing one sets IsActive to No (How to Remove an Item Without Deleting It). The same lookup finds removed items too, so adding a removed name again updates that item and turns it back on instead of creating a second one. That's why the check is existing.IsActive and not just !IsBlank(existing).

Common Mistakes​

MistakeWhat happensDo this instead
Checking only the nameThe same name can't be used for another job titleCompare every column that makes an item unique
Not trimming the nameLeadership with a space looks newCompare Trim(...)
A range or in in the lookupNot delegated, so only part of the list is checkedUse = with &&

Troubleshooting​

SymptomLikely causeFix
The duplicate is saved anywayThe lookup's conditions don't match how the item is storedCompare the same columns that Patch writes
Delegation warning on the lookupA function or operator SharePoint can't runFixed: Delegation Warning

FAQ​

Is the check case-sensitive?​

In my test on SharePoint, no: leadership found Leadership.

Can two people still create the same item at the same moment?​

The check and the save are two steps, so two people who both check before either saves could both save. For a plan that a few managers edit, that's unlikely. Check the list if it matters for your data.

Conclusion​

Look for the item with a delegable LookUp before Patch, and stop with a message that names the item that's already there. Decide up front what counts as the same, and whether a removed item should come back instead of a new one.

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.