Thursday 22 February 2018

DATEDIFF Function in DAX / Power BI


 DATEDIFF Function in DAX

DATEDIFF function is used to get the difference in dates based on the interval we are passing as an argument.

Syntax:
DATEDIFF(<Start_Date>,<End_Date>,Interval)

Parameters:

Start_Date à It can be any Scalar Date Or DateTime value

End_Date à It can be any Scalar Date OrDateTime Value

Interval à It is the interval to be used to compare the dates. Following are the intervals we can use in this argument –
      • DAY
      • WEEK
      • MONTH
      • QUARTER
      • YEAR
      • HOUR
      • MINUTE
      • SECOND

Return Value :
The count of interval boundaries crossed between two dates.

Note: Start_Date cannot be greater than End_Date. It will throw an error if  Start_Date is greater than End_Date.

Examples:

Date_DIFF_In_DAYS = DATEDIFF(Orders[Order Date], TODAY(),DAY) à will return difference in days

Date_DIFF_In_MONTHS = DATEDIFF(Orders[Order Date], TODAY(),MONTH) à Will Return difference in months

Date_DIFF_In_WEEKS = DATEDIFF(Orders[Order Date], TODAY(),WEEK) ) à Will Return difference in weeks

Date_DIFF_In_QUARTERS = DATEDIFF(Orders[Order Date], TODAY(),QUARTER) ) à Will Return difference in Quarters

Date_DIFF_In_YEARS = DATEDIFF(Orders[Order Date],TODAY(),YEAR) ) à Will Return difference in Years

Following is the output of above calculations:

No comments:

Post a Comment