Hi Michael,
I recently explored a few approaches for a similar scenario we encountered, sharing them below:
Scenario 1 - Calendar Days in a Chart
If calendar days are acceptable, Pega v25.1 supports built-in Calculations inside Insights. You can add a Difference in days function directly in the Insight:
Function: Difference in days
Earlier datetime value: Create datetime (pxCreateDateTime - available in the dropdown)
Later datetime value: Now
Set this as a Measure and Case ID as the Dimension. This gives one bar per case with no additional rules needed.
Limitation: this counts all days including weekends. For true business days, see below.
Scenario 2 - True Business Days (Worked well with table)
For business days excluding weekends, the value needs to be calculated using Pega’s Business Calendar function and persisted to the database. Insights queries the database directly, so runtime-only values will not show in charts.
Approach A - Declare Expression
- Create a BusinessDays (Integer) property on your case class, optimized for reporting
- Create a Declare Expression with Recalculate: Always and the following expression:
@BusinessCalendar.differenceBetweenDays( .pxCreateDateTime, @CurrentDateTime(),true, “default”)
The third parameter true is what excludes weekends via the Business Calendar.
- Also set the same value in pyDefault Data Transform so it is persisted on case creation
- Once cases are saved, drag BusinessDays into Insights as a field for table view or as a Measure for chart view
This avoids the job scheduler concern you mentioned entirely. The Declare Expression recalculates when the case is accessed rather than through a batch run, so there are no locked case conflicts.
Approach B - Response Data Transform of a Data Page
If your case is always loaded via a Data Page, you can set the same expression in the Response Data Transform. The trade-off is that the value only persists if the case is explicitly saved afterward, and Data Page caching can affect reliability.
One important prerequisite: If cases are not persisted to the database, Insights will return no results regardless of how the properties and calculations are configured.
Hope this helps. Happy to clarify any of the steps.