Search code examples
powerappspowerapps-canvaspowerapps-formula

Error Message in If operator while using color code


I am receiving the below error message when I write the code in fill option in powerapps.

enter image description here

My code as below

If(
   ('User Input - Unit'.Selected.Value = "ABC") && ('User Input - Application'.Selected.Value = "XXX") && Value('Output'.Text) > 80 ||
    ('User Input - Unit'.Selected.Value = "DEF") && ('User Input - Application'.Selected.Value = "XXX") && Value('Output'.Text) > 360,
    RGBA( 220, 20, 60, 1 ), RGBA( 127, 255, 212, 1 ));
    If(
    ('User Input - Unit'.Selected.Value = "GHI") && ('User Input - Application'.Selected.Value = "XXX") && Value('Output'.Text) > 40 ||
    ('User Input - Unit'.Selected.Value = "JKL") && ('User Input - Application'.Selected.Value = "XXX") && Value('Output'.Text) > 180,
    RGBA( 220, 20, 60, 1 ), RGBA( 127, 255, 212, 1 ));


Solution

  • The ; operator (chaining operator) is used to execute multiple operations together - but it only works in a behavior property. Fill is a data property, so you cannot use it there.

    From the expression it seems like you want to have the fill be one of two colors (RGBA(220, 20, 60, 1) or RGBA(127, 255, 212, 1)). If you want the first color to be chosen if any of the two conditions are true, then you can use the Or function (or operator) to combine those:

    If(
       ('User Input - Unit'.Selected.Value = "ABC") && ('User Input - Application'.Selected.Value = "XXX") && Value('Output'.Text) > 80 ||
        ('User Input - Unit'.Selected.Value = "DEF") && ('User Input - Application'.Selected.Value = "XXX") && Value('Output'.Text) > 360 ||
        ('User Input - Unit'.Selected.Value = "GHI") && ('User Input - Application'.Selected.Value = "XXX") && Value('Output'.Text) > 40 ||
        ('User Input - Unit'.Selected.Value = "JKL") && ('User Input - Application'.Selected.Value = "XXX") && Value('Output'.Text) > 180,
        RGBA( 220, 20, 60, 1 ), RGBA( 127, 255, 212, 1 )
    

    Notice that this works because the || operator has a lower priority than the && operator, but I find it useful to be more explicit and use parenthesis to make it clearer:

    If(
       (('User Input - Unit'.Selected.Value = "ABC") && ('User Input - Application'.Selected.Value = "XXX") && Value('Output'.Text) > 80) ||
        (('User Input - Unit'.Selected.Value = "DEF") && ('User Input - Application'.Selected.Value = "XXX") && Value('Output'.Text) > 360) ||
        (('User Input - Unit'.Selected.Value = "GHI") && ('User Input - Application'.Selected.Value = "XXX") && Value('Output'.Text) > 40) ||
        (('User Input - Unit'.Selected.Value = "JKL") && ('User Input - Application'.Selected.Value = "XXX") && Value('Output'.Text) > 180),
       RGBA( 220, 20, 60, 1 ),
       RGBA( 127, 255, 212, 1 ))
    

    Or even use the Or function (which behaves the same as the || operator):

    If(
      Or(
        ('User Input - Unit'.Selected.Value = "ABC") && ('User Input - Application'.Selected.Value = "XXX") && Value('Output'.Text) > 80,
        ('User Input - Unit'.Selected.Value = "DEF") && ('User Input - Application'.Selected.Value = "XXX") && Value('Output'.Text) > 360,
        ('User Input - Unit'.Selected.Value = "GHI") && ('User Input - Application'.Selected.Value = "XXX") && Value('Output'.Text) > 40,
        ('User Input - Unit'.Selected.Value = "JKL") && ('User Input - Application'.Selected.Value = "XXX") && Value('Output'.Text) > 180
      ),
      RGBA( 220, 20, 60, 1 ),
      RGBA( 127, 255, 212, 1 ))