Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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

1 ACCEPTED SOLUTION
amitchandak
Super User
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

View solution in original post

7 REPLIES 7
amitchandak
Super User
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

When I tried this solution, it said the syntax for date is incorrect. Do you know how to resolve this issue?

Anonymous
Not 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.

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.

Anonymous
Not applicable

@amitchandak 

 

But sometimes I want to report YTD March in May.
Therefore I will need the slicer, I think.

Yes. Refer the slicer is giving me YTD, as do not have data in 2020.

Screenshot 2020-02-03 18.54.52.pngScreenshot 2020-02-03 18.55.14.png

Anonymous
Not applicable

Ok. I should have just believed you.

 

Thank you!👍

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors