0
0
Power-biHow-ToBeginner ยท 3 min read

How to Use DATESYTD in DAX in Power BI: Simple Guide

Use the DATESYTD function in DAX to get all dates from the start of the year up to a specified date in your data. It helps calculate year-to-date values like sales or totals in Power BI reports by filtering dates within the current year.
๐Ÿ“

Syntax

The DATESYTD function syntax is:

  • DATESYTD(dates_column, [year_end_date], [filter])

dates_column: A column with dates to evaluate.

year_end_date (optional): The fiscal year end date as a string, e.g., "12/31" for calendar year.

filter (optional): Additional filter to apply.

DAX
DATESYTD(<dates_column>, [year_end_date], [filter])
๐Ÿ’ป

Example

This example shows how to create a measure that calculates total sales year-to-date using DATESYTD:

DAX
Total Sales YTD =
CALCULATE(
    SUM(Sales[Amount]),
    DATESYTD(Calendar[Date])
)
Output
If today is 2024-06-15, this measure sums all sales from 2024-01-01 to 2024-06-15.
โš ๏ธ

Common Pitfalls

Common mistakes when using DATESYTD include:

  • Not using a proper continuous date column in the dates_column argument.
  • Forgetting to use a date table marked as a date table in Power BI, which can cause incorrect results.
  • Not specifying year_end_date when your fiscal year does not end on December 31.

Example of a wrong and right usage:

DAX
/* Wrong: Using a non-date column */
Total Sales YTD Wrong =
CALCULATE(
    SUM(Sales[Amount]),
    DATESYTD(Sales[OrderID])
)

/* Right: Using a proper date column */
Total Sales YTD Right =
CALCULATE(
    SUM(Sales[Amount]),
    DATESYTD(Calendar[Date])
)
๐Ÿ“Š

Quick Reference

ParameterDescriptionExample
dates_columnColumn of dates to evaluateCalendar[Date]
year_end_dateOptional fiscal year end date"06/30" for June 30 fiscal year end
filterOptional filter expressionFILTER(Sales, Sales[Region] = "West")
โœ…

Key Takeaways

DATESYTD returns all dates from the start of the year to the current date in the context.
Always use a continuous date column from a marked date table for accurate results.
Specify the fiscal year end date if your year does not end on December 31.
Combine DATESYTD with CALCULATE to create year-to-date measures like sales totals.
Avoid using non-date columns in DATESYTD to prevent errors.