Forum Discussion
aforapple_27
1 year agoFrequent Visitor
How can I assign Single value to a variable dynamically?
Amount for Previous Year = var prevYear = Calculate(SELECTEDVALUE('Raw data'[Year])-1) var prevYearFinal = prevYear return CALCULATE(SUM('Raw data'[Amount]), 'Raw data'[Year] IN {2024}) Abov...
Ashish_Mathur
Super User
1 year agoHi,
Assuming you already have a date column in the fat table (and if you do not have it, you will create it), try the following approach
- Create a Calendar table with a calculated column to extract the Year
- Create a relationship (Many to One and Single) from the Date column of the Fact table to the Date column of the Calendar table
- To your slicer, drag Year from the Calendar table and select a Year there
- Write these measures
Total = SUM('Raw data'[Amount])
Total in PY = calculate([Total],previousyear(calendar[date]))
Hope this helps.