The TOTALYTD function evaluates an expression from the first day of the year of the current context to the last day of the current context.
TOTALYTD(
expression,
dates
[, filter]
[, year_end_date]
)
- expression: Expression that returns a scalar.
- dates: Column containing dates.
- filter: Optional argument. Filter to apply to the current context.
- year_end_date: Optional argument of type string. Date that defines the last day of the year to be considered (if it is not specified, it defaults to December 31).
The TOTALYTD function returns a scalar representing the expression given as the first argument evaluated for dates between the first day of the year in the current context and the last day in the current context.
The year_end_date argument is a text string in the same format as that used for the dates on the client's machine where the workbook was created. Only the day and the month are considered.
This function identifies the last day of the current context and considers all dates from the first day of the year to which that day belongs to the last day. This means that if more than one year is involved in the current context, only the last one is considered.
The following functions are equivalent:
TOTALYTD(expression, dates[, filter][, year_end_date])
CALCULATE(expression, filter, DATESYTD(dates[, year_end_date]))
If we consider the following table containing information on sales:
...we define the following measure:
Ventas = SUM(Ventas[Importe])
...and then we define the measure Ventas YTD that calculates the total sales from the beginning of the year of the current context to the last date of the current context:
Ventas YTD = TOTALYTD(
Ventas[Ventas],
Calendario[Fecha]
)
If we take this last measure to a matrix, we obtain:
It can be seen how the measure is reset to zero at the beginning of each year.