I looked at this topic, and did some testing my self, and hope this can help you.
I created a program indicator with the following config:
Aggregation type = Count
Analytics type = Event
Analytics period boundaries
Event date - Before end of reporting period
and event date - after start of reporting period
In expression: V{event_count}
In filter: d2:hasValue(#{CWaAcQYKVpq.bl7EMKxJIIT})
Filter saying that the data element need to have a value in the program stage.
In data visualizer when choosing ngelehun I will only get the number of events where the data element has a value, and this seems to count the right number for me. This includes active and completed enrollments and active and completed events
If you want to filter only active events add: && V{event_status} == ‘ACTIVE’ in filter.
Documentation on functions and variables is available here
Could you please test this in your instance?
Caroline