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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Context Variable Types...
Power Apps
Unanswered

Context Variable Types Are Incompatible Error When Setting Global Variable

(0) ShareShare
ReportReport
Posted on by 29,989 Moderator

While building my latest app I encountered an error that was new to me

 

"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"

 

I have two questions:

1.  In general, what does this error mean and when does it occur?

2.  What might be triggering the error in my code?  I have supplied all 3 code blocks from my app where the error occurred.

 

Code Block #1  (from button OnSelect property)

 

Set(GalleryLevels,{
 CurrentLevel:1,
 Level1:Blank(),
 Level2:Blank(),
 Level3:Blank()}
);


Code Block #2  (from button OnSelect property)

 

Set(GalleryLevels,{
 CurrentLevel:GalleryLevels.CurrentLevel-1,
 Level1:If(GalleryLevels.CurrentLevel=2,Blank(),GalleryLevels.Level1),
 Level2:If(GalleryLevels.CurrentLevel=3,Blank(),GalleryLevels.Level2),
 Level3:If(GalleryLevels.CurrentLevel=4,Blank(),GalleryLevels.Level3)}
);


Code Block #3  (from gallery OnSelect property)

 

Set(GalleryLevels,{
 CurrentLevel:GalleryLevels.CurrentLevel+1,
 Level1:If(GalleryLevels.CurrentLevel=1,gal_drilldownProjects.Selected.Item,GalleryLevels.Level1),
 Level2:If(GalleryLevels.CurrentLevel=2,gal_drilldownProjects.Selected.Item,GalleryLevels.Level2),
 Level3:If(GalleryLevels.CurrentLevel=3,gal_drilldownProjects.Selected.Item,GalleryLevels.Level3)}
);

 

Categories:
I have the same question (0)
  • Verified answer
    timl Profile Picture
    36,383 Super User 2025 Season 2 on at

    Hi @mdevaney 

    This type of error happens when we attempt to store values of differing data types in a variable.

    Here's a simple example of how to recreate this problem.

     

    Set(varTest, 1);
    Set(varTest, "1")

     

    This block of code would trigger the error because on the first line, we're storing a numeric value in varTest and on the second line, we're storing a string value.

    To diagnose this problem, I would investigate the data types that you're storing. What is the data type of GalleryLevels.Level1? Does gal_drilldownProjects.Selected.Item return a value that matches the data type of GalleryLevels.Level1? If not, you can apply the Text or Value functions when you Set variables to make sure that data types are consistent.

    Hope that's of some help.

  • Verified answer
    yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hey @mdevaney 

     

    I think the issue here is the difference between the type returned by Blank() and the gal_drilldownProjects.Selected.Item
     
    I am assuming that the Item returned from gallery is of type Text. To resolve the error, can you try to update your expression as:
     
    Set(GalleryLevels,{
        CurrentLevel:1,
        Level1:"",
        Level2:"",
        Level3:""}
    );
     
    Set(GalleryLevels,{
        CurrentLevel:GalleryLevels.CurrentLevel-1,
        Level1:If(GalleryLevels.CurrentLevel=2,"",GalleryLevels.Level1),
        Level2:If(GalleryLevels.CurrentLevel=3,"",GalleryLevels.Level2),
        Level3:If(GalleryLevels.CurrentLevel=4,"",GalleryLevels.Level3)}
    );
     
    Set(GalleryLevels,{
        CurrentLevel:GalleryLevels.CurrentLevel+1,
        Level1:If(GalleryLevels.CurrentLevel=1,gal_drilldownProjects.Selected.Item,GalleryLevels.Level1),
        Level2:If(GalleryLevels.CurrentLevel=2,gal_drilldownProjects.Selected.Item,GalleryLevels.Level2),
        Level3:If(GalleryLevels.CurrentLevel=3,gal_drilldownProjects.Selected.Item,GalleryLevels.Level3)}
    );
     
    Hope this Helps!
     
    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
  • mdevaney Profile Picture
    29,989 Moderator on at

    @timl 

    Your brief explanation was perfect, thank you!  I was able to test your example and the same error appeared.  Replicating the issue in a simple example really helped my understanding here.

     

    I've coded in a few other languages. Some languages make you declare the variable type (e.g. C++) and other languages don't require type declarations (e.g. Python).  I did not expect the variable type to become enforced in PowerApps because it did not make me explicitly declare the type.

     

    Every language has its quirks: it's all part of the fun of learning!

  • mdevaney Profile Picture
    29,989 Moderator on at

    @yashag2255 

    Your intuition was correct and the solution you provided worked 100%.  Thank you for taking the time to look at my problem and get me unstuck.

     

    I conducted an experiment based on what you taught me.  Using this code in the OnStart property of my app I was able to make all of the errors disappear without changing any other code.  Now I understand the data type can be set by some placeholder value and then immediately set to Blank() afterwards.  Both of our approaches would appear valid.

     

    Set(GalleryLevels,{
     CurrentLevel:1,
     Level1:"blank_value",
     Level2:"blank_value",
     Level3:"blank_value"}
    );
    Set(GalleryLevels,{
     CurrentLevel:1,
     Level1:Blank(),
     Level2:Blank(),
     Level3:Blank()}
    );

    FYI, my current project includes building a Gallery that allows the user to drill-down into financial transactions much like a PivotTable.  Thanks to your code I got it working!

     

  • timl Profile Picture
    36,383 Super User 2025 Season 2 on at

    Glad you managed to fix your problem @mdevaney

    Thanks for all your hard work and contributions to this forum by the way. I'm sure lots of people here really appreciate your help!

     

  • mdevaney Profile Picture
    29,989 Moderator on at

    @timl 
    Thank you for the compliment!  I think having an active forum is important to the success of PowerApps.  I've learned alot from reading the posts here so I wanted to try helping others too.  I haven't particpated on messageboards much in the past but I must admit I am having fun problem solving on this one.

     

    See you in the forums!

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard