Forum Discussion

lazzarjovvch74's avatar
8 years ago
Solved

Can't compare value of type integer

Hi,

I created the next measure but got an error saying that doesn't support comparing values of type integer with values of type Text.

Measure 1 = IF(HASONEVALUE('MyTable'[Year]), CALCULATE(AVERAGE('MyTable'Price]), 'MyTable'[Year] = FORMAT(VALUES('MyTable'[Year])-1,BLANK())))

Just to emphasize that column Year is of type INTEGER. If I convert the column 'Year' to type Text, the above formula works, but I want to keep it as integer. Any idea how I can rewrite this formula?

Thanks

  • TomMartens's avatar
    TomMartens
    8 years ago

    Silly me,

     

    you have to rewrite your measure this way

    Measure 1 =  
    IF(HASONEVALUE('MyTable'[Year]),
        CALCULATE(
            AVERAGE('MyTable'[Price])
            ,FILTER(
                ALL('MyTable'[Year])
                ,'MyTable'[Year] = MAX('MyTable'[Year])-1
            )
        )
        ,BLANK()
    ) 

    I'm sorry for my confusion.

    Regards,
    Tom

     

5 Replies

  • Hey,

    I'm wondering why you not just use this

    ... 'MyTable'[Year] = 'MyTable'[Year]-1

    Regards,
    Tom

    • lazzarjovvch74's avatar
      lazzarjovvch74
      Icon for Helper I rankHelper I

      Hi,

      I tried that but an error appeared (red line under 'MyTable'[Year]):

       

      • TomMartens's avatar
        TomMartens
        Icon for Super User rankSuper User

        Silly me,

         

        you have to rewrite your measure this way

        Measure 1 =  
        IF(HASONEVALUE('MyTable'[Year]),
            CALCULATE(
                AVERAGE('MyTable'[Price])
                ,FILTER(
                    ALL('MyTable'[Year])
                    ,'MyTable'[Year] = MAX('MyTable'[Year])-1
                )
            )
            ,BLANK()
        ) 

        I'm sorry for my confusion.

        Regards,
        Tom