Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Hung_Nguyen_889
New Member

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 " SELECTEDVALUE(DIM_DATE[fin_year])-1 ", the data just show to Week 5 (second picture).

I tried in another way, but I got and error. (3th picture)

Please help me to understand and how to fix this case.

Thank you very much

 

2020_hardCode.PNG

 

2020_variable.PNG

 

2020_error.PNG

 

2 ACCEPTED SOLUTIONS
Payeras_BI
Solution Sage
Solution Sage

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.

Payeras_BI_0-1611652255465.png

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

 

Payeras_BI_1-1611654189144.png

 

Regards,

If this post answered your question, please mark it as a solution to help other users find useful content.
Kudos are another nice way to acknowledge those who tried to help you.

J. Payeras
Mallorca, Spain

View solution in original post

v-yingjl
Community Support
Community Support

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.

View solution in original post

7 REPLIES 7
v-yingjl
Community Support
Community Support

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.

Payeras_BI
Solution Sage
Solution Sage

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.

Payeras_BI_0-1611652255465.png

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

 

Payeras_BI_1-1611654189144.png

 

Regards,

If this post answered your question, please mark it as a solution to help other users find useful content.
Kudos are another nice way to acknowledge those who tried to help you.

J. Payeras
Mallorca, Spain
wdx223_Daniel
Community Champion
Community Champion

maybe SELECTEDVALUE get a blank on those rows.

Thank you for your response,

SELECTEDVALUE got 2020 value. It still showed data from week 1 to week 5. 😞

try to chante your measure

RETURN _Previous_Year

 

Payeras_BI
Solution Sage
Solution Sage

Hi @Hung_Nguyen_889 ,

 

Try with this instead:

 

PY REVENUE =
CALCULATE ( [Total Revenue $], SAMEPERIODLASTYEAR ( DIM_DATE[date] ) )

 

Regards,

If this post answered your question, please mark it as a solution to help other users find useful content.
Kudos are another nice way to acknowledge those who tried to help you.

J. Payeras
Mallorca, Spain

Hi @Payeras_BI 

Thank you for your response,

I can't use SAMEPERIODLASTYEAR function. Because, our financial date is different.

The fist date of 2020 is starting at '2019-12-29' and the ending date is '2021-01-02'

The fist date of 2021 is starting at '2021-01-03' and the ending date is '2022-01-01'

So, it is incorrect when I use SAMEPERIODLASTYEAR

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.