Forum Discussion
YTD For All Years
- 4 years ago
Hi rioshox
The key to solving the problem is to get the respective period of each year according to the month selected by the slicer. Firstly, you need to have an independent date table, use it as slicer.
(1) create the Date table
(2) create the measure bellow,
Measure = var _selectedMonth = MONTH(SELECTEDVALUE('Date'[Date])) var _currentMonth = DATE(YEAR(MIN('Table'[Date])),_selectedMonth,1) var _dateStart = EDATE(_currentMonth,-12) return CALCULATE(SUM('Table'[value]),FILTER(ALL('Table'),'Table'[Date] >= _dateStart && 'Table'[Date] <= _currentMonth))as you can see above, if you select 2022-Jan, then _currentMonth = 2022 - Jan, _dateStart = 2021 - Jan, then Measure returns total of this period.
But if you want to get same period in last years, try this
Measure2 = var _selectedMonth = MONTH(SELECTEDVALUE('Date'[Date])) return CALCULATE(SUM('Table'[value]),FILTER(ALL('Table'),MONTH('Table'[Date])= _selectedMonth && YEAR('Table'[Date])= year(MIN('Table'[Date]))))Besides, if you want to add total to this visual, try this
Measure2-1 = var _selectedMonth = MONTH(SELECTEDVALUE('Date'[Date])) return CALCULATE(SUM('Table'[value]),FILTER(ALL('Table'),MONTH('Table'[Date])= _selectedMonth && YEAR('Table'[Date])= year(MIN('Table'[Date]))))Measure2-2 = var _selectedMonth = MONTH(SELECTEDVALUE('Date'[Date])) return SUMX(FILTER(ALL('Table'),MONTH('Table'[Date])= _selectedMonth),[Measure2-1])Measure2 = IF(ISINSCOPE('Table'[Date].[Year]),[Measure2-1],[Measure2-2])Best Regards,
Community Support Team _Tang
If this post helps, please consider Accept it as the solution to help the other members find it more quickly.
Hi,
For a basic YTD calculation you can use pattern like this: CALCULATE([Your measure],DATESYTD('Calendar'[Date])). Then to get your desired end result you can add to this LY, LY-1, LY-2 and so on. Do you have a set amount of years you want to calculate together (e.g. 4) or all the years for all time? If this is the case we might need a different dax.
This DAX resets every year and adds all the values prior to the max month:
I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!
My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/