Forum Discussion

MKPA's avatar
MKPA
Regular Visitor
2 years ago
Solved

SELECTEDVALUE Error

Hello, I encountered an error with DAX measure. 

The error is: 

A function SELECTEDVALUE has been used in a scalar predicate filter expression. This is not allowed

 

The measure is: 

CALCULATE([product_count],all(DIM_PRODUCT), DIM_PRODUCT[PRODUCT_GROUP] = SELECTEDVALUE(DIM_PRODUCT[PRODUCT_GROUP]) &&
DIM_PRODUCT[PRODUCT_SUPGROUP] = SELECTEDVALUE(DIM_PRODUCT[PRODUCT_SUPGROUP]))

 

how to fix this error? 

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi MKPA ,

     

    Thanks for the reply from Uzi2019 , please allow me to provide another insight:

     

    Problems arise with direct use in Filter expressions because the Filter context therein requires Boolean expressions or Table Filter expressions, rather than using scalar values directly.

     

    You can use variables to store SELECTEDVALUE(DIM_PRODUCT[PRODUCT_GROUP]) and SELECTEDVALUE(DIM_PRODUCT[PRODUCT_SUPGROUP]), and then replace them with your original Measure syntax, for example:

    Measure = 
    VAR _a= SELECTEDVALUE(DIM_PRODUCT[PRODUCT_GROUP])
    VAR _b= SELECTEDVALUE(DIM_PRODUCT[PRODUCT_SUPGROUP])
    RETURN
        CALCULATE(
            [product_count],
            ALL(DIM_PRODUCT),
            DIM_PRODUCT[PRODUCT_GROUP] = _a,
            DIM_PRODUCT[PRODUCT_SUPGROUP] = _b
        )

     

    If that does not solve your problem, please provide the pbix file to help you further, and remember not to log into your account when uploading the pbix file in Power BI Desktop.

     

    If you have any other questions please feel free to contact me.

     

    Best Regards,
    Yang
    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

2 Replies

  • Uzi2019's avatar
    Uzi2019
    Community Champion

    Hi MKPA 
    Try to use VALUES() instead of selectedvalues.

     

    I hope It may resolved your issue!

     

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi MKPA ,

     

    Thanks for the reply from Uzi2019 , please allow me to provide another insight:

     

    Problems arise with direct use in Filter expressions because the Filter context therein requires Boolean expressions or Table Filter expressions, rather than using scalar values directly.

     

    You can use variables to store SELECTEDVALUE(DIM_PRODUCT[PRODUCT_GROUP]) and SELECTEDVALUE(DIM_PRODUCT[PRODUCT_SUPGROUP]), and then replace them with your original Measure syntax, for example:

    Measure = 
    VAR _a= SELECTEDVALUE(DIM_PRODUCT[PRODUCT_GROUP])
    VAR _b= SELECTEDVALUE(DIM_PRODUCT[PRODUCT_SUPGROUP])
    RETURN
        CALCULATE(
            [product_count],
            ALL(DIM_PRODUCT),
            DIM_PRODUCT[PRODUCT_GROUP] = _a,
            DIM_PRODUCT[PRODUCT_SUPGROUP] = _b
        )

     

    If that does not solve your problem, please provide the pbix file to help you further, and remember not to log into your account when uploading the pbix file in Power BI Desktop.

     

    If you have any other questions please feel free to contact me.

     

    Best Regards,
    Yang
    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!