Using the DATEDIFF function
The DATEDIFF
function returns the values between two dates given a specific date interval. You can use this function to determine the number of days between today and the first day of the year. You could also calculate the number of months between date values.
Available options for the date interval are:
SECOND
MINUTE
HOUR
DAY
WEEK
MONTH
QUARTER
YEAR
Getting ready
Create a new measure to calculate the minimum date in the Calc_Date_T. This value will be used to calculate the number of years from the first crash reported to today. In this case, 11/27/2016:
Open the Model.bim to the Calc_Date_T table.
In the measure creation area, click on an empty cell to create a measure to minimum date:
Min_Crash_Date:=MIN(Calc_Date_T[CRASH_DATE])
How to do it...
In the measure creation area, click on an empty cell to create a measure to return the current date and time:
Years_Since_First_Accident:=DATEDIFF( [Min_Crash_Date],TODAY(), YEAR)
The result...