Forum Discussion
DAX: Date Difference required with New Measure
- Anonymous8 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
- Anonymous7 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.
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
Hi Anonymous Master,
Hope you are doing good.
The below provided Date Diffarence DAX is working fine.
DDiff_DueDateCloDate = VAR Due = MAX ( 'Task'[DueDate] ) VAR Clos = MAX ( 'Task'[ClosedDate] )
RETURN IF ( Clos > Due, DATEDIFF ( Due, Clos, DAY ), DATEDIFF ( Clos, Due, DAY ) )
I need some change from the Output
Example about DueDate & ClosedDate.
| ClosedDate | DueDate | Diffarence |
| 9/20/2018 | 9/26/2018 | 6 |
| 9/29/2018 | 9/26/2018 | -3 |
-- If ClosedDate is lessthan the DueDate output noofdays (+Positive number)
-- If ClosedDate is Greatherthan the DueDate output noofdays (-Negative number)
Please help me out this Master :)
- Anonymous7 years agoNot applicable
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.
- ssvr7 years ago
Helper III
Thank you so much Anonymous DAX Master :-)
- ssvr7 years ago
Helper III
Hi Anonymous,
One doubt from my end. Its a new one :-)
While applying below DAX i got one error.,
truecondiation = IF(ISM[OData_{CH} Recommend0]=BLANK(),ISM[OData_{RNSP} TSS_x00],ISM[OData_{CH} Recommend0])
Expressions that yield variant data-type cannot be used to define calculated columns.
Can you fix this for me.
- ssvr7 years ago
Helper III
Hi Anonymous
I have one doubt
I want to create a Date Hirachy for one of the existing date columns/measure
I will enclosed the example screen shot for your reference
Please help me out