Forum Discussion
rks
Resolver II
2 years agoReturn 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: ...
- 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] ) )
devesh_gupta
Impactful Individual
2 years agorks Try modifying your measure as follow to make your __TableVariable consistently a table. Try if it works for you:
VAR __TableVariable=
IF(
ISFILTERED( 'Product'[Color] ),
VALUES( 'Product'[Color] ),
ALL( 'Product'[Color] )
)
RETURN
CALCULATE(
SUM( 'Product Forecast'[Value] ),
TREATAS ( __TableVariable , 'Product Forecast'[Color] )
)
If you find this insightful, please provide a Kudo and accept this as a solution.