cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Super User
Super User

Context Variable Types Are Incompatible Error When Setting Global Variable

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)}
);

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Super User
Super User

Re: Context Variable Types Are Incompatible Error When Setting Global Variable

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.

View solution in original post

Dual Super User
Dual Super User

Re: Context Variable Types Are Incompatible Error When Setting Global Variable

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!

View solution in original post

6 REPLIES 6
Super User
Super User

Re: Context Variable Types Are Incompatible Error When Setting Global Variable

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.

View solution in original post

Dual Super User
Dual Super User

Re: Context Variable Types Are Incompatible Error When Setting Global Variable

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!

View solution in original post

Super User
Super User

Re: Context Variable Types Are Incompatible Error When Setting Global Variable

@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!

Super User
Super User

Re: Context Variable Types Are Incompatible Error When Setting Global Variable

@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!

 

Super User
Super User

Re: Context Variable Types Are Incompatible Error When Setting Global Variable

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!

 

Super User
Super User

Re: Context Variable Types Are Incompatible Error When Setting Global Variable

@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!

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,508)