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
Yoojin
Frequent Visitor

Date column in DATESYTD

Hi all,

 

I have a question about why I must use a date column from a date table, not a data table, for DATESYTD.

I do know I should use a date column in a date table for the argument but I don't think I fully understand how it works..

 

I have created the two tables below for comparison. The first one has a Date column from the Calendar table as the argument for DATESYTD and it works the way it should. The second one however does not retreive YTD sales amount.

 

I would like to know why the InvoiceDate in the Sales table is not working the same way. I expected it would make no difference because the InvoiceDate column contains dates too and the DATESYTD could do the math with having all the valid dates.

 

DATESYTD with the date column in the Calendar date table

 

 

[Total Net Sales YTD] = CALCULATE([Total Net Sales], DATESYTD(Calendar[Date]))

 

 

MonthTotal Net SalesTotal Net Sales YTD
Jan$1,250,000$1,250,000
Feb$1,000,000$2,250,000
Mar$1,500,000$3,750,000
Apr$2,000,000$5,750,000
May$1,700,000$7,450,000
Jun$1,800,000$9,250,000
Jul$2,000,000$11,250,000
Grand Total$11,250,000$11,250,000

 

 

DATESYTD with the date column in the Sales data table

 

 

[Total Net Sales YTD] = CALCULATE([Total Net Sales], DATESYTD(Sales[InvoiceDate]))

 

 

MonthTotal Net SalesTotal Net Sales YTD
Jan$1,250,000$1,250,000
Feb$1,000,000$1,000,000
Mar$1,500,000$1,500,000
Apr$2,000,000$2,000,000
May$1,700,000$1,700,000
Jun$1,800,000$1,800,000
Jul$2,000,000$2,000,000
Grand Total$11,250,000$11,250,000

 

Could anyone help me understand the reason why the reference to dates in a data table instead of a date/calendar table is not working? Thank you and excuse my ignorance.

1 ACCEPTED SOLUTION
v-binbinyu-msft
Community Support
Community Support

Hi @Yoojin ,

DATESYTD() is a time-intelligence function, If you want these functions to work properly, a date table that holds consecutive dates is a prerequisite for it.

vbinbinyumsft_0-1662621757222.png

For more details, you can read related document: DATESYTD – DAX Guide

 

Best regards,
Community Support Team_ Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

5 REPLIES 5
v-binbinyu-msft
Community Support
Community Support

Hi @Yoojin ,

DATESYTD() is a time-intelligence function, If you want these functions to work properly, a date table that holds consecutive dates is a prerequisite for it.

vbinbinyumsft_0-1662621757222.png

For more details, you can read related document: DATESYTD – DAX Guide

 

Best regards,
Community Support Team_ Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

VIJAYKUMART
Resolver I
Resolver I

You need create 2 relationships with Calender Table

1.  calender date to sales date - active relationship - represents with line 

2. calender date to Invoice date  - inactive relationship - represents with dotted line (---)

write DAX like below 

[Total Net Sales YTD] = CALCULATE([Total Net Sales], USERELATIONSHIP(CALENDER(DATE), SALES(INVOICEDATE)),DATESYTD(Sales[InvoiceDate]))

Thanks VIJAYKUMART. I already created a relationship between the Invoice Date in the Sales table and the Date column in the Calendar table. 🙂 Otherwise how could I get the first result using DATESYTD? What I wanted to know was, why DATESYTD wasn't working with the Invoice Date column in the data table (Sales) even though it contains dates too. Given the comments the other friends left, it seems to have something to do with consecutiviness of dates...? Anyway, thanks for your help and letting me know the USERELATIONSHIP DAX!

Ashish_Mathur
Super User
Super User

Hi.

I think there are 2 valid reasons for working with a Calendar Table rather than the invoice date column of your Data Table:

  • The Calendar Table has consecutive dates including public holidays and weekends.  The invoice date column may not have consecutive dates
  • By creating a Calendar Table, you can create relationships from multiple tables to it 

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
speedramps
Super User
Super User

Only Power BI novices use in build date functions

 

It is best pratice to use a calendar table  with  year and month offsets

see https://www.youtube.com/watch?v=BtYn1hfdSAM

and https://www.youtube.com/watch?v=5RB3Jdfrn1s

 

do all these training modules and yoy will never go back to using DATESYTD again

 

A calendar table with offsets it a much better way to calculate MTD, YTD, PM and PY

 

Thanks for reaching out for help.

I put in a lot of effort to help you, now please quickly help me by giving kudos.

Remeber we are unpaid volunteers and here to coach you with Power BI and DAX skills and techniques, not do the users job for them. So please click the thumbs up and accept as solution button. 

If you give someone a fish then you only give them one meal, but if you teach them how to fish then they can feed themselves and teach others for a lifetime.  I prefer to teach members on this forum techniques rather give full solutions and do their job. You can then adapt the technique for your solution, learn some DAX skills for next time and soon become a Power BI Super User like me. 

One question per ticket please. If you need to extend your request then please raise a new ticket.

You will get a quicker response and each volunteer solver will get the kudos they deserve. 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.