Forum Discussion
How can I assign Single value to a variable dynamically?
Hi aforapple_27 ,
I see what’s going wrong now thanks for the clarification.
The issue happens because when a month has no data in 2025, the context carries over and blocks the 2024 data from showing too.
I’ve updated the measure to fix this by ensuring the 2024 data still appears even if 2025 is blank:
Amount for Previous Year =
VAR prevYear = SELECTEDVALUE('Raw data'[Year]) - 1
RETURN
CALCULATE(
SUM('Raw data'[Amount]),
TREATAS(
VALUES('Raw data'[Month]),
'Raw data'[Month]
),
'Raw data'[Year] = prevYear
)
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.
Hi aforapple_27 ,
I wanted to check if you had the opportunity to review the information provided and also thank you Ashish_Mathur for your inputs. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you.