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

Replacing NOW() with blank dates to calculate days difference

Hi All,

I am trying to calculate the days difference between two dates e.g. create and resolved some tickets are not resolved hence the dates are blank so to handle that i created "Resolved 2" however i use this in the "Incident Age 2" formula its given me wierd result (see below) not sure why. For the dates which are not blank the result is correct. What am i doing wrong? 

NOTE: i cannot use DATEDIFF because it gives output in integer and i need it in float.
 
Formula to handle blanks
Resolved 2 = IF(vw_incident[resolved_at]=BLANK(),NOW(),vw_incident[resolved_at])
 
Formula to calculate age
Incident Age 2 = IF(MIN(vw_incident[resolved_at])=BLANK(),1* [Resolved2]-MIN(vw_incident[create_date]),1*
MIN(vw_incident[resolved_at])-MIN(vw_incident[create_date]))
 
Output:
shariqjoy_New_0-1604871465145.png

 

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

Note you can use DATEDIFF to return the result in hours or minutes too, and then divide by 24, etc. to get days in decimal form.  You could also use your Resolved 2 expression in a variable and use that in your Age measure (instead of a separate measure).

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

5 REPLIES 5
mahoneypat
Employee
Employee

Note you can use DATEDIFF to return the result in hours or minutes too, and then divide by 24, etc. to get days in decimal form.  You could also use your Resolved 2 expression in a variable and use that in your Age measure (instead of a separate measure).

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

@mahoneypat  i just noticed a slight difference in the result , please see below. The result for the below example should 8.95 but with our calculation its coming up 8.96 what could be wrong ?

 

shariqjoy_0-1604927091376.png

 

 

Looks like a rounding error.  Maybe return MINUTES in the DATEDIFF instead?

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

@mahoneypat  i returned it in SECONDS and then divided by /24/60/60 to convert it in days and it solved the issue.

Anonymous
Not applicable

@mahoneypat  thanks for this, it was the simplest solution and it worked for me. Kudos to you.

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