Skip to main content

Fixed: "Incompatible Types for Comparison. These Types Can't Be Compared: Number, Error" in Power Apps

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

Incompatible types for comparison. These types can't be compared: Number, Error. means one side of a comparison has already failed. In my case, a duplicated screen compared a number with a context variable that only the original screen receives. The fix is to give the new screen its own variable.

What I Was Doing​

I was adding the Competency screen to the Career Development Plan app (Part 9). Its layout matches the Review screen from Part 8: a header with Back, a title and Refresh, a scrolling body, a text box with a character count and a row of two buttons. So instead of building it again, I duplicated the Review screen (How to Duplicate a Screen in Power Apps).

The Review screen loads its response in its Refresh button. One line of that formula reads the response by its ID:

btnRefreshRVS → OnSelect (part)
LookUp(
CompetencyResponses,
ID = locResponseId
)

What I Expected​

A copy named Review Screen_1 that I could rename and change, step by step.

What I Got​

The copy appeared, and so did a red ⊗ next to its Refresh button and a red dot on the App checker icon. The App checker's Formulas list had two errors, both on the copy's Refresh button:

The App checker's Formulas pane with Errors (2) under Review Screen_1 (2): Name isn't valid. 'locResponseId' is... and Incompatible types for comparison..., both on btnRefreshRVS_1 .OnSelect

In the expanded formula bar, the = in ID = locResponseId was underlined, and so was locResponseId. Pointing at the = showed:

The expanded formula bar of the copied Refresh button with ID = locResponseId underlined in red and a hover box reading Incompatible types for comparison. These types can't be compared: Number, Error., with View Problem and No quick fixes available

Errors
Incompatible types for comparison. These types can't be compared: Number, Error.
Name isn't valid. 'locResponseId' isn't recognized.

What I Checked​

The comparison has two sides. ID is the SharePoint item's ID, a number. The second message says locResponseId isn't a valid name on this screen. A name Studio can't resolve becomes an error, so the comparison was Number against Error, which is exactly what the first message says.

On the original Review screen, the same formula has no errors. The difference is where locResponseId comes from. The Team Member screen's waiting list opens the Review screen with it:

galPendingTMS → OnSelect
Navigate('Review Screen', ScreenTransition.None, {locResponseId: ThisItem.ID})

Microsoft's article on variables gives context variables the scope Screen: you reference them from only one screen (Understand variables in canvas apps). The Navigate reference says its record sets context variables on the target screen (Navigate function). Nothing navigates to the copy with locResponseId, so on the copy it doesn't exist.

Why It Happens​

Duplicating a screen copies its formulas, not the variables other screens send to it. Any formula on the copy that reads such a variable gets Name isn't valid. If the variable is used in a comparison, Studio also reports the comparison, because one side is now an error. It's the same cause as Fixed: "The '.' Operator Cannot Be Used on Error Values", where the failed name was on the left of a dot.

The Fix​

Give the new screen its own variables, then make its formulas use them. I did it in this order, which Fixed: "Name Isn't Valid" explains: first the Navigate that creates the variables, then the formulas that read them.

  1. On the Team Member screen, the plan rows open the renamed copy, Competency Screen, with the competency's ID and the job title:

    galPlanTMS → OnSelect
    Navigate('Competency Screen', ScreenTransition.None, {locCompetencyId: ThisItem.ID, locJobTitle: locMemberJobTitle})
  2. I replaced the copy's loader with one that reads locCompetencyId instead of locResponseId:

    btnRefreshCS → OnSelect
    UpdateContext({locIsLoading: true, locIsSaving: false, locConfirmRemove: false});
    Refresh(RoleCompetencies);
    UpdateContext(
    {
    locCompetency: If(
    IsBlank(locCompetencyId),
    Blank(),
    LookUp(
    RoleCompetencies,
    ID = locCompetencyId
    )
    )
    }
    );
    Reset(txtNameCS);
    UpdateContext({locIsLoading: false})

After the Fix​

Both errors were gone. In their place, the App checker listed 45 others, all of the same kind: Name isn't valid. 'locReview' isn't recognized. and The '.' operator cannot be used on Error values. on the copied labels and buttons:

The App checker's Formulas pane with Errors (45) under Competency Screen (45), starting with Name isn't valid. 'locReview' isn't... and The '.' operator cannot be used... on btnBackCS .AccessibleLabel

That was expected. locReview was created by the old loader, which I had just replaced, and the copied controls still read it. Each error went away when its control got the Competency screen's own formula. With the screen finished, the Formulas section had no count left:

The App checker with Formulas, Runtime, Performance and Data source showing no count and Accessibility (12)

The 12 accessibility results are the screen headings explained in Fixed: "Missing Tab Stop", two on each screen's title.

Common Mistakes​

MistakeWhat happensDo this instead
Rewriting the comparison, for example Value(locResponseId)The name error stays and the result is still wrongFix the name: give the screen its own variable
Writing the new loader before the Navigate that creates its variableName isn't valid on the new variableWrite the Navigate first
Expecting zero errors right after the new loaderControls that read the old variables still failChange each copied control's formulas, one by one

Troubleshooting​

SymptomLikely causeFix
The same message with Text, Error or Boolean, ErrorThe failed side of the comparison has a different typeSame fix: find the name that isn't valid
The error is on a formula you didn't copyThe variable isn't created anywhereFixed: "Name Isn't Valid"
The '.' operator cannot be used on Error values on copied labelsThey read a record variable from the old screenFixed: "The '.' Operator Cannot Be Used on Error Values"

FAQ​

Why does Studio show two errors for one mistake?​

Each part of the formula is checked. The name is invalid, and the comparison that uses it fails too. Fix the name and both disappear.

Would a global variable avoid this?​

It would remove the error, but the value would then be shared by every screen. Passing the value with Navigate keeps it on the screen that needs it.

Conclusion​

These types can't be compared: Number, Error points at a comparison, but the cause is the side that's an error. After duplicating or copying, look for a context variable that only the original screen receives, give the new screen its own through Navigate, and replace the formulas that read the old 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.