Forum Discussion
YTD with Slicer
Hello, I'm getting mad...
I would like to represent turnover YTD, but I would like to use a slicer to determine when YTD ends. That means I would like to set the slicer to April in the middle of May and then YTD will be calculated until 31.04. Can you tell me how this is possible?
Thank you very much and best regards
For YTD, you can use datesytd and totalytd. You can try add filter to restrict the month
YTD Sales = var _max = maxx(date,endofmonth(dateadd(date[date],-1,Month))) return CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date])),'Date'[Date]<=_max)To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s.
Refer
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges
Connect on Linkedin
7 Replies
- amitchandak
Super User
For YTD, you can use datesytd and totalytd. You can try add filter to restrict the month
YTD Sales = var _max = maxx(date,endofmonth(dateadd(date[date],-1,Month))) return CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date])),'Date'[Date]<=_max)To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s.
Refer
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges
Connect on Linkedin- AnonymousNot applicable
amitchandakThank you for your fast response. But I forgott to mention, that I wamt to use a slicer to select the YTD-Month/-Year.
So I tried this:
Sales YTD =var _selected_month = SELECTEDVALUE(Dates[Month])var _selected_year = SELECTEDVALUE(Dates[Year])return CALCULATE(Sum('Sales'[Amount]);Dates[Month] <= _selected_month;Dates[Year] <= _selected_year)But it doesn't work.
- amitchandak
Super User
If you do not select the date from slicer, datesytd, and totalytd will take the last date of the calendar. make sure your month year is in date dimension table.
- AnonymousNot applicable
When I tried this solution, it said the syntax for date is incorrect. Do you know how to resolve this issue?