<!-- https://learnsql.cpetoday.com/functions/dax/totalytd -->
# TOTALYTD

Language: DAX
Category: Time intelligence: to date
Syntax: TOTALYTD(<expression>, <dates> [, <filter>] [, <year_end_date>]). Without a filter, the year end date goes in the third position, as in the examples below.
Summary: Evaluates an expression from the start of the year up to the last date in the filter context.
Returns: A value (a scalar).
Level: Intermediate
Related: DATESYTD, TOTALQTD, TOTALMTD, CALCULATE, CLOSINGBALANCEYEAR

## What it does
TOTALYTD gives a running total for the year. For a month in the report, it adds up every month from the start of the year to that month. Finance teams use it for revenue and expense year to date, for budget versus actual year to date, and for cumulative cash flow. With a year end argument, it follows a fiscal year that ends on a date other than December 31.

## Syntax and arguments
- expression: the measure to total, such as [Total Revenue]. Required.
- dates: the date column of the Calendar table, such as 'Calendar'[Date]. Required. Use the Calendar column, not the date column of the fact table.
- filter: an optional filter, such as 'Sales'[Channel] = "Retail". Optional. If you use a filter and a year end date, the filter comes third and the year end date fourth.
- year_end_date: the fiscal year end as text in the form month/day, such as "6/30" for a June 30 year end. Optional. When there is no filter, it goes in the third position.

## Example
A company has a June 30 year end. In the March 2027 column of a report, the controller wants revenue from the start of the fiscal year, which is July 1, 2026, through March 31, 2027.

```dax
Revenue YTD (June year end) =
TOTALYTD([Total Revenue], 'Calendar'[Date], "6/30")
```

The measure uses the Calendar's dates to find the fiscal year that contains March 2027, then adds up revenue from July 1, 2026 through the last date in the context. Without the year end text, the total would start on January 1, 2027 and miss the July to December months.

## Example: a second, different use
Retail channel revenue year to date, for the same June year end. The filter is the second argument after the dates, so the year end goes in the fourth position.

```dax
Retail Revenue YTD =
TOTALYTD(
    [Total Revenue],
    'Calendar'[Date],
    'Sales'[Channel] = "Retail",
    "6/30"
)
```

## Things to watch
- The dates argument must be the Calendar date column, and the Calendar must be marked as the date table with no gaps. A calendar with missing days gives wrong totals.
- The year end is text in month/day form. "6/30" is correct. A date value or a month name will not work.
- When there is no filter, the year end is the third argument. When there is a filter, it is the fourth.
- A visual with no date on an axis returns the total for the whole filter context, so check the axis before you trust the number.
- For a fiscal year end, the year label is the year in which the fiscal year ends. A date in July 2026 belongs to fiscal 2027 with a June year end.

## In business terms
TOTALYTD is the standard year to date measure in board packs, lender reports and budget tracking. Pair it with a prior year version (see SAMEPERIODLASTYEAR) so that the team can compare the same stage of the year. Getting the fiscal year end right is what makes the YTD total match the general ledger.
