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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
admin_xlsior
Post Prodigy
Post Prodigy

DATESYTD not working ?

Hi guys,

 

Can DATESYTD working without any context ?

I have this data like :

admin_xlsior_0-1638814831694.png

Is having this kind of measure :

 

All net sales YTD = CALCULATE(
                        [All net sales],
                        DATESYTD(Dates[Date])
)

 

works ?

 

If based on my table, shouldn't I receive a total of net sales for year of 2021 ? April - Sept 2021 ? Because currently it is blank.

If I click on the row of that table, for example April 1 2021, then the measure is correct, returned the exact value (87,800), but when none selected which is what I want because I only need the total of sales "up-to-this-year" which mean I do not need that table, then it returned blank.

 

Thanks

 

1 ACCEPTED SOLUTION
ValtteriN
Super User
Super User

Hi,

If I understood your problem correctly you would like to have YTD measure in a KPI card or something similar to that? Based on the problem description I think your slicer selection is not working as you would hope and thus you get the blank value.  Instead of Datesytd you could use the following approach:

My test data:

ValtteriN_0-1638823011715.png

Ideal outcome:
So in this example the goal is that without any slicers the YTD measure would return 350. That is this year's running total until today. If something is selected the calculation should be done until the selected day. So for example If I select 4.12.2021 the calculation would be from this time period: 1.1.2021-4.12.2021.

Measure using datesbetween ([Base measure] is just SUM of [Value]):

YTD from base =
var test = HASONEFILTER(YTD_Example[Date])
var _sdate = if(test,DATE(YEAR(SELECTEDVALUE(YTD_Example[Date])),1,1), DATE(YEAR(TODAY()),1,1))
var _edate = if(test,MAX(YTD_Example[Date]),TODAY()) return
CALCULATE([Base measure],DATESBETWEEN(YTD_Example[Date],_sdate,_edate))

 

End result:
Without selection (calculates until today):

ValtteriN_1-1638823214065.png

With date selected (calculates until selection:

ValtteriN_2-1638823275878.png

Hopefully this can be used to resolve your issue and if it does accept this as a solution!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
VahidDM
Super User
Super User

Hi @admin_xlsior 

 

You need to add a Calendar [Date] table to your model to use time intelligence DAX functions.

Use this link to add that calendar: https://www.vahiddm.com/post/creating-calendar-table-with-3-steps

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

ValtteriN
Super User
Super User

Hi,

If I understood your problem correctly you would like to have YTD measure in a KPI card or something similar to that? Based on the problem description I think your slicer selection is not working as you would hope and thus you get the blank value.  Instead of Datesytd you could use the following approach:

My test data:

ValtteriN_0-1638823011715.png

Ideal outcome:
So in this example the goal is that without any slicers the YTD measure would return 350. That is this year's running total until today. If something is selected the calculation should be done until the selected day. So for example If I select 4.12.2021 the calculation would be from this time period: 1.1.2021-4.12.2021.

Measure using datesbetween ([Base measure] is just SUM of [Value]):

YTD from base =
var test = HASONEFILTER(YTD_Example[Date])
var _sdate = if(test,DATE(YEAR(SELECTEDVALUE(YTD_Example[Date])),1,1), DATE(YEAR(TODAY()),1,1))
var _edate = if(test,MAX(YTD_Example[Date]),TODAY()) return
CALCULATE([Base measure],DATESBETWEEN(YTD_Example[Date],_sdate,_edate))

 

End result:
Without selection (calculates until today):

ValtteriN_1-1638823214065.png

With date selected (calculates until selection:

ValtteriN_2-1638823275878.png

Hopefully this can be used to resolve your issue and if it does accept this as a solution!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Mikelytics
Resident Rockstar
Resident Rockstar

HI @admin_xlsior ,

 

For DatesYTD you need date filter context.

 

Measure

Mikelytics_3-1638821424464.png

 

 

without fitler context

Mikelytics_0-1638821311424.png

 

with filter context

Mikelytics_1-1638821333601.png

other filter context (here 2020 is ignored since I also chose something from 2021)

Mikelytics_2-1638821393840.png

 

________________________

If this post helps, then please Accept it as the solution to help other community members find it more quickly

Click on the Thumbs-Up icon if you like this reply.

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

Hi both,

 

Thanks, I thought it does not need context for this particular function, but it does. Initially I do not intent to have any slicer for this time. 

 

@ValtteriN , this is so cool. 

 

Thanks

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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