Forum Discussion

rks's avatar
rks
Resolver II
2 years ago
Solved

Return a Table Statement from IF-condition (for TREATAS)

Hi folks,   I receive an error message: The TREATAS function expects a table expression for argument '1', but a string or numeric expression was used.   I have the following measure:       ...
  • leomureb's avatar
    1 year ago

    Hi,

     

    I was having the same issue as you and adding the variable inside {} in the TREATAS function solved my issue.

     

    Try this:

    VAR __TableVariable=
        IF(
            ISFILTERED( 'Product'[Color] ),
            VALUES( 'Product'[Color] ),
            { "#all_colors" }
        )
    RETURN
        CALCULATE(
            SUM( 'Product Forecast'[Value] ),
            TREATAS ( {__TableVariable} , 'Product Forecast'[Color] )
    )