Is it possible to calculate difference between 2 date fields and show the result in reports using PA

tyagisu
Mega Expert

Hi,

I have a requirement to show the difference between RCA Delivery Date and Problem Record Open Date from problem record. I need to show the avg of those records with assignment groups in row and months in a column.

Something like this:

find_real_file.png

Any help would be appreciated.

Thanks in advance,

Su

 

1 ACCEPTED SOLUTION

A couple of notes:

1) Your calculation calculates days, but your unit displayed is hours. If you want it in hours, you need to change this line:

var hours=function(x,y){return diff(x,y)/(1000 * 60 * 60 * 24);};

To this:

var hours=function(x,y){return diff(x,y)/(1000 * 60 * 60);};

2) Are you sure the calculation is incorrect? Have you calculated what it should be manually?

View solution in original post

7 REPLIES 7

A couple of notes:

1) Your calculation calculates days, but your unit displayed is hours. If you want it in hours, you need to change this line:

var hours=function(x,y){return diff(x,y)/(1000 * 60 * 60 * 24);};

To this:

var hours=function(x,y){return diff(x,y)/(1000 * 60 * 60);};

2) Are you sure the calculation is incorrect? Have you calculated what it should be manually?

Adam Stout
ServiceNow Employee
ServiceNow Employee

I'm highly suspicious of your indicator source.  Are you sure it is historically safe to collect?  What do the count indicators show?

Adam Stout
ServiceNow Employee
ServiceNow Employee

If you are looking for wall clock duration (not business duration), take a look Database Functions to calculate the datediff: https://docs.servicenow.com/bundle/kingston-application-development/page/build/platform-functions/ta...

You also might consider a field (or scripted metric) that calculates this duration whenever the RCA delivery date.  By adding a new field, you would be able to use this in reports (as a condition or displaying it) and in PA.  If you do it in a PA script, you can only use it in PA.  For some data (like how long something has been open), PA is a good fit, but in many other cases, you really want to consider looking at a field or metric to store the duration.