Dynamic "days since last event" calculation in pivot table

Dear all,

I’m trying to create a pivot table that shows the number of days since the last event created in a tracker capture program. The goal is to monitor whether maintenance is being performed periodically as intended, and to flag water points that are overdue for maintenance.

I created a data element and used the following program rule action:
assign value (d2:daysBetween(V{event_date}, V{current_date}))

This works perfectly at the time of data entry—however, the value remains static. For example, if the days between is 4 today, it will still show 4 tomorrow, even after running data analytics. The only way to update it is to reopen the event and save it again.

Is there a way to make this calculation dynamic (i.e., always reflect the current number of days since the last event) without having to manually re-save events?

Thank you.

Hi @Mr_jorge

Thank you for this question. You’re already on the right track with one minor difference, you’d need to use a Program Indicator instead of a Program Rule. In a program rule, “current_date” is the date of the program rule’s execution whereas in a program indicator, “current_date” is the date whenever the analytics run.

The expression would instead be:
d2:daysBetween(PS_EVENTDATE:<programStageUID>, V{current_date})
As explained in the docs functions to use in program indicators:

‘PS_EVENTDATE:(programStageUid) to compare the latest event date from a given program stage.’

Please know that if we use a program indicator of enrollment type, analytics will need to be rerun for the values to be updated; however, if we had used only the “event_date” it will get the latest event date in all of the program stages within the program.

Please give it a try and let us know how it goes. Thanks!

Thank you so much. It worked perfectly. I am currently trying to transition some forms away from SurveyCTO, as I believe DHIS2 may be able to handle the follow-up functions and dashboard functionalities more effectively.

Your help is truly appreciated. If I eventually win the race, I will definitely let you know so we celebrate. :grinning_face_with_smiling_eyes: :tada:

Hi George!

Always happy to help… :folded_hands:Thanks for your kind words!:heart:

Any updates? :grin:

Yes. Got the task. Starting development now. The QR code scan function which was part of last year’s LMIS training in Rwanda will be needed for this module. I’ll check back here for the setup steps once I am at that point. Thank you @Gassim

That’s great news! Thanks for the update. Looking forward to your next topic .. :slight_smile: