OR logic In Event Reports

Hi everyone,

Does DHIS2 by default support OR logic in Event Reports?

Thanks

Hi @dmbantu

Would you please explain further what do you mean? If you can share an example of what you have in mind please…

Thanks!

Hi, dmbantu

Yes, DHIS2 supports OR logic in Event reports, but only in specific scenarios or with a workaround.

Scenario 1: Using OR within the Same Data Element

In this instance, you can use OR logic when filtering for multiple values within the exact same data element (e.g., Vaccine equals ‘BCG’ OR ‘OPV’).

This can be done via the following steps:

  1. In the Event Reports or Event Visualizer app, add a filter for the data element you need.

  2. Choose the in operator (or select multiple checkboxes/options if it’s an Option Set).

  3. Enter or select all the desired values (e.g., ‘BCG’, ‘OPV’).

The DHIS2 engine interprets all values entered in the in operator as an OR condition, matching any of the listed values.

Scenario 2: Using OR Across Different Data Elements (DE_A OR DE_B)

If you need true OR logic across two different data elements (e.g., DE_A = ‘X’ OR DE_B = ‘Y’), the standard Event Reports UI won’t work, because it ANDs every separate filter line together.

However, here is a recommended workaround that may work for you. Try this to implement custom logic directly within DHIS2 for reuse in reports, dashboards, and line lists.

  1. Create an Indicator: Go to Maintenance > Program indicators.

  2. Define the OR Logic: Create an expression that tests both conditions and outputs a ‘1’ if either is true (OR), and ‘0’ otherwise.

    • Conceptual Example: d2:condition( “(#{DE_A} = ‘X’) || (#{DE_B} = ‘Y’)”, 1, 0 )

    • Example Scenario: For events where fever = ‘Yes’ OR cough = ‘Yes’, the expression would be: d2:condition(“(#{fever} = ‘Yes’) || (#{cough} = ‘Yes’)”, 1, 0).

  3. Apply as Filter: Use the new Program Indicator in your Event Report or Line Listing, filtering for cases where the indicator equals 1.

Please always test your program indicator expressions in a staging instance or with a small dataset . Syntax and supported functions vary slightly by DHIS2 version.

1 Like

Hi @e4eDHIS2,

For our scenario, I think “Option 2 seems like the best choice.” because we have two data elements from two different stages. We want to view data if S1_DE = yes or S2_DE = yes.

Thanks

2 Likes