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
JBeyers
Helper III
Helper III

DAX: YTD and MTD questions

Hi all,

 

I have two questions regarding the calculation of YearToDate and MonthToDate:

 

1) I do not have unique timestamps in my dataset. I'm not able to use DAX functions like TOTALYTD() because my timestamps are not unique. How do I solve this?

 

2) I want to compare YTD values of the current year with the average YTD values of previous years. How do I calculate the average YTD values of previous years?

 

Thanks in advance!

1 ACCEPTED SOLUTION

@joeort Depending on what you have access to, you can create a date dimension table in SQL, or Excel.. There are a bunch of different posts on how to create these. Below are just a few.

 

SQL:

http://www.bidn.com/blogs/MikeDavis/ssis/1519/create-date-dimension-with-fiscal-and-time

or

http://sqldusty.com/2012/04/12/create-date-dimension-script/

 

Excel:

http://msbiacademy.com/?p=4731

or

http://kohera.be/en/blog/detail/how-to-create-a-date-table-in-powerpivot-with-one-single-value-2


Looking for more Power BI tips, tricks & tools? Check out PowerBI.tips the site I co-own with Mike Carlo. Also, if you are near SE WI? Join our PUG Milwaukee Brew City PUG

View solution in original post

7 REPLIES 7
WillT
Community Admin
Community Admin

You could also use the CALENDARAUTO() function to create a new Calculated Table with a unique column of dates from elsewhere in your model. HTH!
kcantor
Community Champion
Community Champion

You could try creating a DIMDATE table to relate to your data. This table could be used for unique time stamps. I use one and link it to my performance table. It allows me to use YTD and MTD.





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

Proud to be a Super User!




How did you create your DIMDATE table? Does anything change in PowerBI Desktop vs PowerPivot (which I was easily running time intelligence calcs).?

@joeort Depending on what you have access to, you can create a date dimension table in SQL, or Excel.. There are a bunch of different posts on how to create these. Below are just a few.

 

SQL:

http://www.bidn.com/blogs/MikeDavis/ssis/1519/create-date-dimension-with-fiscal-and-time

or

http://sqldusty.com/2012/04/12/create-date-dimension-script/

 

Excel:

http://msbiacademy.com/?p=4731

or

http://kohera.be/en/blog/detail/how-to-create-a-date-table-in-powerpivot-with-one-single-value-2


Looking for more Power BI tips, tricks & tools? Check out PowerBI.tips the site I co-own with Mike Carlo. Also, if you are near SE WI? Join our PUG Milwaukee Brew City PUG

I had similar difficulty on a first pass through YTD functions and then all was revealed when I created a Date table and then joined that back to my parent table's date field. 

 

YTD Sales = TOTALYTD(sum('Parent Sales Report'[Sales]),'Parent Sales Report'[Date])

     does not yield what I expected (ie. Feb is not Feb + Jan) 

YTD Sales = TOTALYTD(sum('Parent Sales Report'[Sales]),SeparateDateTable[Date])

magically does (Feb = Feb + Jan) 

 

@Baskar has a nice post here to make the date table using the Advanced Editor. 

https://community.powerbi.com/t5/Desktop/How-do-i-create-a-date-table/td-p/23896

 

 

Here's my preferred date table based on another solution in the same suggested post. I've made some modifications and additions. The formulas are also copy-and-paste ready so you won't run into any curvy quote errors. https://sharepointlibrarian.com/2018/02/12/how-to-create-a-powerful-date-table-or-datekey-in-power-b...

Greg_Deckler
Super User
Super User

Sample data would help tremendously, otherwise, we really have no idea what you are dealing with or how to specifically help you beyond mere generalities.

 

So, here are some generalities. http://www.daxpatterns.com. Check out the Time Intelligence patterns that do not rely on DAX Time Intelligence functions.

 

You could create a unique date/time table. From your data, you could create a second query, only pull in the date/time column and specify "unique values only". Boom, unique date/time table. Then you just relate your data table to this date/time table. There are also free date/time tables in the Azure Data Marketplace. DateStream and Date Dimension are two examples.

 

Finally, you could do something like this =AVERAGEX(FILTER('MyTable',[YEAR]=2014),[Value])

 

You could also just do an AVERAGE([Value]) and then put that in a matrix with YEAR as a row and this new measure as a column and then it will automagically be filtered by the rows in the matrix.

 

Again, impossible to really get specific without sample data or something to go on.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.