Forum Discussion

Hung_Nguyen_889's avatar
Hung_Nguyen_889
New Member
5 years ago
Solved

Formula issue - SELECTEDVALUE

Hi guys, I have issue when using the SELECTEDVALUE. If I hard-code year number ( 2020 ), the data of "PY Revenue" shows in all weeks. (first picture). And it's vice versa, I replace 2020 value by ...
  • Payeras_BI's avatar
    5 years ago

    Hi Hung_Nguyen_889 ,

     

    It is hard to tell without checking your pbix file (consider sharing a sample if you still cannot sort this out) but, to rule out a possible cause, make sure the filter you have placed in your Filter Pane (fin_year = 2021) comes also from the DIM_DATE table.

    I tried your formula with some dummy data and works fine when filtering as said before. See below:

     

     

    Regards,

  • v-yingjl's avatar
    5 years ago

    Hi Hung_Nguyen_889 ,

    As the error message describes, SELECTEDVALUE() could not be used as a T/F expression with a filter expression in the formula, you can use a variable to store it and use it in CALCULATE() function as @ Payeras_BI mentioned.

    In addition, you can also add a FILTER() function in the formula to quote SELECTEDVALUE() directly which is allowed in DAX:

    PY Revenue =
    CALCULATE (
        [Total Revenue $],
        FILTER (
            ALL ( 'DIM_DATE' ),
            DIM_DATE[fin_year]
                = SELECTEDVALUE ( DIM_DATE[fin_year] ) - 1
        )
    )
    

     

    Best Regards,
    Community Support Team _ Yingjie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.