web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Conflict using Set and...
Power Apps
Suggested Answer

Conflict using Set and Patch

(0) ShareShare
ReportReport
Posted on by
I've been writing an app for work.  In App.OnStart I initialize a global variable called varUser and populate it is a record with multiple fields such as name, email, orgSymbol, role, etc.
Set(varUser, {
     name:Office365Users.MyProfileV2().displayName,
     email:Office365Users.MyProfileV2().userPrincipalName,
     role:First(Filter('Personnel DB',email = Office365Users.MyProfile().UserPrincipalName)).role,
     org:First(Filter('Personnel DB',email = Office365Users.MyProfile().UserPrincipalName)).org
     }
);
That seems to work fine.  I'm able to use varUser.org and varUser.role throughout my app. But then I need to change one of them based upon a dropdown list.
 
Set(varUser, Patch(varUser, {
     role:dropDownRole.Selected.Value,
     org:dropDownOrg.Selected.Value
    }
));
And that fails.
 
Incompatible type. We can't evaluate your formula because the context variable types are 
incompatible with the types of values in other places in your app.
 
What gives?  role and org are both text values in the Personnel DB.  The drop down items are all text.  What am I doing wrong?
Categories:
I have the same question (0)
  • Suggested answer
    WarrenBelz Profile Picture
    155,111 Most Valuable Professional on at
    I am not sure if you have some mis-types in the second code, but I tested this here and it worked fine. 
     
    I used your code (small suggestion below) for setting the Variable using a similar list I have here (both role and org are Single Lines of Text
    With(
       {
          _User: LookUp(
             'Personnel DB',
             email = Office365Users.MyProfile().UserPrincipalName
          )
       },
       Set(
          varUser,
          {
             name: Office365Users.MyProfileV2().displayName,
             email: Office365Users.MyProfileV2().userPrincipalName,
             role: _User.role,
             org: _User.org
          }
       )
    );
    then this patched the new text values I had from two single selection drop-downs - I assume Value is the correct output for yours.
    Set(
       varUser, 
       Patch(
          varUser, 
          {
             role: dropDownRole.Selected.Value,
             org: dropDownOrg.Selected.Value
          }
       )
    );
     
    Please Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like
    Visit my blog
    Practical Power Apps    LinkedIn  
  • Suggested answer
    11manish Profile Picture
    1,537 on at
    The error occurs because Power Apps inferred a different data type (likely a record such as a Choice or Lookup) for role and org when the variable was first initialized, but you are later trying to assign plain text values.
     
    To fix this, either normalize the fields to text from the beginning or maintain the same record structure when updating.
     
    Also, avoid using Patch on variables—use Set with a full record update instead.
  • Suggested answer
    TechFreak Profile Picture
    58 on at

    Hi,

    The issue you’re facing is due to how Power Apps handles record typing for variables.

    What’s happening

    When you initialize varUser in App.OnStart, Power Apps infers a fixed schema (structure + data types) for that record based on the initial values:

     
    Set(varUser, {
    name: Office365Users.MyProfileV2().displayName,
    email: Office365Users.MyProfileV2().userPrincipalName,
    role: First(Filter('Personnel DB', email = Office365Users.MyProfile().UserPrincipalName)).role,
    org: First(Filter('Personnel DB', email = Office365Users.MyProfile().UserPrincipalName)).org
    })
     

    Now varUser.role and varUser.org are typed based on what comes from 'Personnel DB'.

     

    Why your Patch fails

    This line:

     
    Set(varUser, Patch(varUser, {
    role: dropDownRole.Selected.Value,
    org: dropDownOrg.Selected.Value
    }))
     
     

    fails because:


    • Patch() is meant for data sources, not for updating local records

    • It tries to merge records with potentially different inferred types

    • Even if both look like text, Power Apps may treat them differently internally (e.g., Choice vs Text)
       

    Correct approach (Update record directly)

    Use record update syntax instead of Patch:

     
    Set(
    varUser,
    {
    name: varUser.name,
    email: varUser.email,
    role: dropDownRole.Selected.Value,
    org: dropDownOrg.Selected.Value
    }
    )

    Cleaner approach using With() or record merge

    If you want a more maintainable way:

     
    Set(
    varUser,
    varUser & {
    role: dropDownRole.Selected.Value,
    org: dropDownOrg.Selected.Value
    }
    )
     
     

    Pro Tip

    If your dropdown is bound to Choices(...), sometimes .Value vs .Result matters. If you still see issues, verify using:
     

    ​​​​​​​JSON(dropDownRole.Selected)
     
     

    Summary


    • Patch() is not suitable for updating local variables

    • Power Apps enforces strict record typing once a variable is initialized

    • Use record reassignment or merge (&) to update fields

    •  

     

    If this resolves your issue, please mark the answer as accepted and give it a like. It helps others in the community and supports knowledge sharing. Thanks!

  • WarrenBelz Profile Picture
    155,111 Most Valuable Professional on at
    Please note that the long ChatGPT copy/paste response is completely incorrect (in may ways) - you certainly can update a Table Variable. 
     
    I probably need to remind responders that it is important to follow The Responsible AI policies for the Community so the content can be considered in the proper context.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 516

#2
WarrenBelz Profile Picture

WarrenBelz 450 Most Valuable Professional

#3
Vish WR Profile Picture

Vish WR 448

Last 30 days Overall leaderboard