Forum Discussion
How can I assign Single value to a variable dynamically?
Hi @,
Thank you for using Microsoft Community Forum. Also thankyou hnguy71 for your inputs.
The problem is due to context behavior in Power BI:
- SELECTEDVALUE() works in slicer context, but when the measure evaluates row-by-row (like in a table), that slicer context doesn’t hold the same way.
- Totals work because the context aggregates the whole data set — but rows go blank because the row itself doesn’t "see" the slicer’s value properly.
Try this measure, I have tried with some sample data in my end it worked fine:
Amount for Previous Year =
VAR prevYearFinal = SELECTEDVALUE('Raw data'[Year]) - 1
RETURN
CALCULATE(
SUM('Raw data'[Amount]),
'Raw data'[Year] = prevYearFinal
)
I am also including pbix file for your better understanding, please have a look into it.
I hope this will reslove your issue, if you need any further assistance, feel free to reach out.
If this post helps, then please give us Kudos and consider Accept it as a solution to help the other members find it more quickly.
Thankyou.
Hello,
I tried your code but still it didn't work unfortunately in my case.