Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ssvr
Helper III
Helper III

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 Created = MAX('Dates'[CreatedDt])
VAR Closed = MAX('Dates'[ClosedDt])
VAR dd=-1
IF (Closed>Created) {
dd=DATEDIFF(Created;Closed;days)
} else {
dd= DATEDIFF(Closed;Created;days)
}
RETURN dd

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

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

View solution in original post

Anonymous
Not 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.

View solution in original post

21 REPLIES 21

Thanks I got dis

But I want to incorporate this one into previous DAX query (Daydiff)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors