## How does the YEARFRAC function (DAX) work?

The YEARFRAC function calculates a fraction of the year between two dates, representing the number of whole days. Use the YEARFRAC worksheet function to identify the proportion of benefits or obligations that must be assigned to a specific term for an entire year.

## YEARFRAC Formula Syntax

= YEARFRAC (
<start_date>, <end_date>, <basis>
)

## How do you use the YEARFRAC function?

You can use the YEARFRAC function to identify the proportion of the benefits or obligations of an entire year to be assigned to a particular term.

## Related Support Forum Posts

Total Years of Service of Employees in the department
Understanding DAX Formula
Developing Complex Dax functions

## Considerations when using the YEARFRAC function

If start_date or end_date are not valid dates, YEARFRAC returns an error.

If basis < 0 or if basis > 4, YEARFRAC returns an error.

## Formula examples using the YEARFRAC function

The following example returns the fraction of a year which is the difference between the dates in the two columns, TransactionDate and ShippingDate:

=YEARFRAC(Orders[TransactionDate],Orders[ShippingDate])

The example below gives the fraction of a year represented by the difference between the dates 1 January and 1 March:

=YEARFRAC("Jan 1 2007","Mar 1 2007")

Whenever possible, use four-digit years to avoid getting unexpected results. The current year is assumed, when the the year is truncated. The first date of the month is assumed when the date is or is omitted.

The second argument, basis, has also been omitted. Therefore, the year fraction is calculated according to the US (NASD) 30/360 standard.