Performance Analytics - Need help with metric indicators

Delta007
Kilo Explorer

Hi Community. I am new in PA, and I got some requirements that I am unsure of. I need to create a report/indicator with the formula = [ age of all open incidents / total open incidents]. 
The age of all open incidents = current date - create date (in days).

 

I guess I need to use the formula indicator for this, but I am not sure how to calculate the age of open incidents and total open incidents. Do I need to create new indicators for them too? If so, which indicators will be best suited for this? 

Any kind of help is very much appreciated.

Thank you.

1 REPLY 1

Pavan Srivastav
ServiceNow Employee

Hello,

 

Welcome to Performance Analytics! Your instinct is correct — you do need a Formula Indicator, and it does require building the component indicators first. Let me walk you through the whole thing from scratch.


What You Are Building

Formula Indicator (Average Age of Open Incidents)
        │
        ├── Indicator A: Total Age of Open Incidents  (sum of days open)
        │
        └── Indicator B: Total Open Incidents         (count)

The formula will be: A ÷ B


Step 1 — Indicator B: Count of Open Incidents

This is the simpler one so build it first.

Navigate to: Performance Analytics → Indicators → Create New

Field Value
Name Open Incidents - Count
Table Incident [incident]
Type Automated
Aggregate Count
Filter State is not Resolved AND State is not Closed
Direction Minimize (fewer open incidents = better)
Unit Records

This gives you a simple count of all currently open incidents — your denominator.


Step 2 — Indicator A: Total Age of Open Incidents

This is the more complex one. You need to sum the age in days across all open incidents. PA cannot directly subtract dates natively in an automated indicator, so you have two options:

Option A — Script Indicator (Recommended)

Navigate to: Performance Analytics → Indicators → Create New

Field Value
Name Open Incidents - Total Age in Days
Table Incident [incident]
Type Manual / Script
Script See below
// Script Indicator — sums age in days across all open incidents
(function(indicator) {

    var totalDays  = 0;
    var now        = new GlideDateTime();

    var gr = new GlideRecord('incident');
    gr.addQuery('state', 'NOT IN', '6,7'); // 6=Resolved, 7=Closed
    gr.query();

    while (gr.next()) {
        var opened = new GlideDateTime(gr.getValue('opened_at'));
        var diff   = GlideDateTime.subtract(opened, now);
        // getDayPart() returns whole days
        totalDays += Math.abs(diff.getDayPart());
    }

    indicator.setValue(totalDays);

})(indicator);

⚠️ Match the state values to your instance — check your incident State choice list to confirm the numeric values for Resolved and Closed.

Option B — Calculated Field Approach

Add a calculated field u_age_in_days on the Incident table that stores the current age, then use a standard Sum automated indicator on that field. This is simpler to set up but adds a field to the table and requires a business rule to keep it current.

Option A is cleaner — no schema changes needed.


Step 3 — Formula Indicator: Average Age

Navigate to: Performance Analytics → Indicators → Create New

Field Value
Name Open Incidents - Average Age (Days)
Type Formula
Direction Minimize
Unit Days

In the Formula field:

A / B

Then map the variables:

Variable Indicator
A Open Incidents - Total Age in Days
B Open Incidents - Count

Step 4 — Data Collection Job

All three indicators need to be added to a Data Collector to populate historical data and run on schedule.

Navigate to: Performance Analytics → Data Collectors → Jobs

Either add your indicators to an existing scheduled job or create a new one:

Field Value
Name Open Incidents PA Collection
Run Daily (recommended — adjust to your needs)
Indicators Add all three indicators above

After saving, click Collect Data Now to populate the first values and verify everything is working before waiting for the scheduled run.


Step 5 — Verify Your Output

Run this in Scripts - Background to manually validate the expected result before trusting the PA indicator:

var totalDays = 0;
var count     = 0;
var now       = new GlideDateTime();

var gr = new GlideRecord('incident');
gr.addQuery('state', 'NOT IN', '6,7');
gr.query();

while (gr.next()) {
    var opened = new GlideDateTime(gr.getValue('opened_at'));
    var diff   = GlideDateTime.subtract(opened, now);
    totalDays += Math.abs(diff.getDayPart());
    count++;
}

gs.info('Total open incidents: ' + count);
gs.info('Total age in days:    ' + totalDays);
gs.info('Average age in days:  ' + (count > 0 ? (totalDays / count).toFixed(2) : 'N/A'));

Compare this output to what your Formula Indicator shows — they should match.


Summary of What to Build

# Indicator Type Purpose
1 Open Incidents - Count Automated / Count Denominator — B
2 Open Incidents - Total Age in Days Script Numerator — A
3 Open Incidents - Average Age (Days) Formula (A÷B) Final metric

The key insight for PA beginners is that Formula Indicators never collect data themselves — they always depend on other indicators doing the actual data collection. You always build the components first, then combine them in the formula.