# Excluding closed enrollments from program indicators without changing past reports

**URL:** <https://community.dhis2.org/t/excluding-closed-enrollments-from-program-indicators-without-changing-past-reports/77260>\
**Category:** Support - Assistance technique\
**Tags:** tracker, analytics\
**Created:** [5 October 2026 20:19 UTC](https://community.dhis2.org/t/excluding-closed-enrollments-from-program-indicators-without-changing-past-reports/77260 "2026-10-05T20:19:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![malekpour](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/malekpour/32/48181_2.png) [@malekpour](https://community.dhis2.org/u/malekpour)\
**Post date:** [5 October 2026 20:19 UTC](https://community.dhis2.org/t/excluding-closed-enrollments-from-program-indicators-without-changing-past-reports/77260/1 "2026-10-05T20:19:28Z")

</div>

Hi everyone,

I’m working on a chronic-care tracker program and ran into something others might know a way to solve.

Our **enrollment** program indicators include things like “lost to follow-up” (no visit in 12 months). The trouble is that a patient who has died also has no visits, so they end up counted as lost to follow-up.

We close the enrollment when a patient dies, so my first idea was to add `V{enrollment_status} == 'ACTIVE'` to the filter. That doesn’t work well, though, because it uses the **current** status. Once a patient’s enrollment is closed, they disappear from all the old reports too, even for periods when they were alive and in care. For example, if enrollment is completed in April 2026, it will be excluded from January 2026 reports too which is obviously wrong.

Currently, what **partially** worked for me is this filter:

`V{enrollment_status} == 'ACTIVE' || V{completed_date} > V{analytics_period_end}`

In plain words: count the patient if they’re still active, or if their enrollment was closed after the period ended. Old reports stay the same. Surprisingly, the docs ([Programs - DHIS2 Documentation](https://docs.dhis2.org/en/use/user-guides/dhis-core-version-243/configuring-the-system/programs.html#program_indicator_functions_variables_operators)) say `V{completed_date}` is the event completion date. But in **enrollment-type** program indicators it’s actually the enrollment completion date (I’ve reported it here: [Jira](https://dhis2.atlassian.net/browse/DHIS2-22225)).

But this workaround is not ideal because of two issues:

1. Enrollment completion date in Capture app is forced as the current date, so if for example the patient passed away 2 months ago, we can’t complete the enrollment with completion date of 2 months ago.
2. This workaround doesn’t work for cancelled enrollments and they are included in the program indicator.

So, in brief, how can we exclude completed/cancelled enrollments from reporting periods **only after** the completion/cancellation date and not from reporting periods before the completion/cancellation.

Thanks!

---

<div class="post-metadata">

**Author:** ![Gassim](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/gassim/32/35347_2.png) [@Gassim](https://community.dhis2.org/u/Gassim)\
**Post date:** [8 October 2026 20:31 UTC](https://community.dhis2.org/t/excluding-closed-enrollments-from-program-indicators-without-changing-past-reports/77260/2 "2026-10-08T20:31:03Z")

</div>

Hi @malekpour

Thank you for taking the time to report this. I see the docs specifically mention that the V{completed\_date} returns “completion date of **event which triggered this rule** ” so the PR needs to be tied to a program stage in order to return the completion date of the event.

Since the PI is an enrollment type program indicator, the V{completed\_date} will return the completion date of the enrollment.

I have a workaround suggestion that I would like to propose. How about utilizing the `d2:lastEventDate` found in PR and assign the date of the last event to a DE (Last Event Date)? This means you will be able to use the DE that contains the date of the last event and avoid the V{completion\_date}.

What do you think of this workaround? So that instead of the following PI filter:

> [@malekpour](#):
>
> V{enrollment\_status} == ‘ACTIVE’ || V{completed\_date} \> V{analytics\_period\_end}

You will compate DE{Last EVENT Date} \> \> V{analytics\_period\_end};

> [@malekpour](#):
>
> So, in brief, how can we exclude completed/cancelled enrollments from reporting periods **only after** the completion/cancellation date and not from reporting periods before the completion/cancellation.

and since the last event date is exactly the last event date, it will continue to appear in the reporting periods before the completion/cancellation regardless.

Please let me know if this works or if I might have missed anything. Thanks!

---

<div class="post-metadata">

**Author:** ![malekpour](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/malekpour/32/48181_2.png) [@malekpour](https://community.dhis2.org/u/malekpour)\
**Post date:** [9 October 2026 14:40 UTC](https://community.dhis2.org/t/excluding-closed-enrollments-from-program-indicators-without-changing-past-reports/77260/3 "2026-10-09T14:40:31Z")

</div>

Hi @Gassim,

Many thanks for your reply and the workaround.

> [@Gassim](#):
>
> I see the docs specifically mention that the V{completed\_date} returns “completion date of **event which triggered this rule** ” so the PR needs to be tied to a program stage in order to return the completion date of the event.

Regarding the docs, I was referring to definition of `completed_date` in “Variables to use in a **program indicator** expression or filter” table and not the “Standard variables to use in **program rule** expressions” table: [Programs - DHIS2 Documentation](https://docs.dhis2.org/en/use/user-guides/dhis-core-version-243/configuring-the-system/programs.html#variables-to-use-in-a-program-indicator-expression-or-filter)

 ![image](https://dhis2.b-cdn.net/uploads/default/original/3X/0/a/0a055e22c4a3c776e23eedca4513bc27dd116472.png)

Regarding using `d2:lastEventDate`, we do not create an event for completion or cancellation of enrollments. Our users simply use below menu in the Capture app to complete or cancel an **enrollment** :

 ![image](https://dhis2.b-cdn.net/uploads/default/original/3X/5/3/53ed3aacfccf910c1217b9ed78d9f179ef6914ab.png)

Thanks again Gassim!

---

<div class="post-metadata">

**Author:** ![Gassim](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/gassim/32/35347_2.png) [@Gassim](https://community.dhis2.org/u/Gassim)\
**Post date:** [7 November 2026 14:57 UTC](https://community.dhis2.org/t/excluding-closed-enrollments-from-program-indicators-without-changing-past-reports/77260/4 "2026-11-07T14:57:35Z")

</div>

Hi again @malekpour!

Sorry for the confusion in my last reply. I was actually wondering if we could make use of Program Rules first to make a record of the last event date? Actually, I want to understand are you looking for the ‘last event date’ or the enrollment ‘completion date’? I assumed that having a ‘last event date’ data element might help but I think I might not have understood the entire scenario properly.

1. A TEI is enrolled in the program
2. The visits continue until (new events each time):  
A) TEI stops visiting (which after 12 months of no visits, is marked as ‘lost to follow-up’)? [maybe here was can create the PR!]  
B) TEI dies (which then at the clinic they simply ‘complete the enrollment’?)

> [@malekpour](#):
>
> Regarding using `d2:lastEventDate`, we do not create an event for completion or cancellation of enrollments. Our users simply use below menu in the Capture app to complete or cancel an **enrollment** :

So what I don’t understand is if the workflow for both ‘lost to follow-up’ vs ‘died/transferred’ is the same, how do you differentiate exactly?

Wouldn’t it make sense to add a Tracked Entity Attribute (TEA) ‘died’ so that it’s easier to exclude the TEIs that die? **In other words, when looking at the form of a specific TEI (regardless of the PIs), how do you differentiate if the TEIs died or is lost to follow-up?**

---

<div class="post-metadata">

**Author:** ![malekpour](https://dhis2.b-cdn.net/user_avatar/community.dhis2.org/malekpour/32/48181_2.png) [@malekpour](https://community.dhis2.org/u/malekpour)\
**Post date:** [9 November 2026 17:06 UTC](https://community.dhis2.org/t/excluding-closed-enrollments-from-program-indicators-without-changing-past-reports/77260/6 "2026-11-09T17:06:17Z")

</div>

Hello again @Gassim,

Thanks for your reply. The scenario is your option B: A TEI is enrolled in a program and visits the clinic until TEI dies which then at the clinic users simply “complete the enrollment”. After that point in time (date of death), the enrollment should be excluded from program indicator calculations.

Regarding your question, we differentiate loss to follow-up from death with the same exact functionality. If TEI doesn’t visit the clinic for 12 months while the enrollment is still “active” (i.e., is not completed as dead), we consider that TEI as lost to follow-up.

While I believe, **user-defined** enrollment completion ( **and** cancellation) date is a valuable data point and should be exposed for use in analytics, your suggestion is a good interim solution. I mean, adding an attribute to TEI as “date of death” instead of relying on enrollment completion date.

Thanks!
