Forum Discussion
Anonymous
4 years agoNot applicable
Calculate Year over Year comparison dynamically based on the [year] slicer
Hello All, I have a question regarding dynamically calculate the year over year comparison. Suppose I have a table that look like this: Sales: 2019 2020 2021 2022 ...
- 4 years ago
Hi Anonymous ,
There's a lot of ways to do this, here's one way:
1) To use time intelligence measures in DAX you need a date table. I created a basic one and marked as the date table using this code:
TableDT =VAR MinYear = YEAR ( MIN ( Table1[Date] ) )VAR MaxYear = YEAR ( MAX ( Table1[Date] ) )RETURNADDCOLUMNS (FILTER (CALENDARAUTO( ),AND ( YEAR ( [Date] ) >= MinYear, YEAR ( [Date] ) <= MaxYear )),"Month Name", FORMAT ( [Date], "mmmm" ),"Month Number", MONTH ( [Date] ))2) Next I created three measures:2a)Current Year = SUM(Table1[Value])2b)Last Year = CALCULATE([Current Year],SAMEPERIODLASTYEAR(Table1[Date]))2c)Chg Year = [Current Year] - [Last Year]That gives me these results:Matrix visual with year slicerSimple Date Table for exampleHere's the PBIX file if you want to review in your desktop application.If you found this helpful, please mark as a solution so others can find it please! Always glad to help! Tom 😀
NickLiu
5 months agoFrequent Visitor
here you go! You may also creat 2 cards to show Current Year vs. Previous Year, and put 2 cards on top of the column headers to make it more user-friendly. full step-by-step instructions: