Forum Discussion

ssvr's avatar
ssvr
Helper III
8 years ago
Solved

DAX: Date Difference required with New Measure

Hi,   Can you help me out with this query   One of my mate share dis DAX (Measure) for date diffarece. But i got some errors with query can you fix this [ClosedDt-CreatedDt]   Daydiff = VAR Cr...
  • Anonymous's avatar
    Anonymous
    8 years ago
    Daydiff =
    VAR Created =
        MAX ( 'Dates'[CreatedDt] )
    VAR Closed =
        MAX ( 'Dates'[ClosedDt] )
    VAR NoOfDays =
        IF (
            Closed > Created,
            DATEDIFF ( Created, Closed, DAY ),
            DATEDIFF ( Closed, Created, DAY )
        )
    RETURN
        IF ( NoOfDays >= 21, "Met SLA", "NotMet SLA" )

    Just created another variable called NoOfDays with the calculation you wanted, then use it in the other if statement

  • Anonymous's avatar
    Anonymous
    7 years ago

    ssvr, this should do it

     

    DDiff_DueDateCloDate = 
    VAR Due = INT( MAX ( 'Task'[DueDate] ) )
    VAR Clos = INT( MAX ( 'Task'[ClosedDate] ) )
    RETURN 
    Due - Clos

    INT() will convert a date into an integer.

     

    Then you simply subtract one number from the other.  This will make the result show a negative number, and should be the fastest performance-wise.