- KB
- Intersection Magic Windows
- Filters / queries
- How to properly use the "OR" (|) operator in a filter expression
Issue
Improper use of the “OR” operator (|) can result in an undesired data set, no data at all, or all data being returned. This article is to help understand its correct use.
Explanation
Suppose you’ve created a filter like this to remove pedestrians from your diagram.
(First_Harmful <> Ped_~school) | (First_Harmful <> Pedestrian)
This filter does not filter any crashes from your diagram.
Solution
Filter statements will always resolved to true or false. When you use an or( | ) statement in your filter you are asking if condition one or condition two is true for each crash record. A true resolution of either condition will include the crash, and only a false resolution of booth conditions will filter the crash.
Here is an example of how (First_Harmful <> Ped_~school) | (First_Harmful <> Pedestrian) would work.
Crash value
Ped_~School ((First_Harmful<>Ped_~School)=False or (First_Harmful<>Pedestrian)=True) statement is true
Pedestrian ((First_Harmful<>Ped_~School)=True or (First_Harmful<>Pedestrian)=False) statement is true
Ped_~School and Pedestrian values would not be filtered from the list of crashes.
The correct way to write this filter would be to use an and statement
(First_Harmful <> Ped_~school) & (First_Harmful <> Pedestrian)
Value used
Ped_~School ((First_Harmful<>Ped_~School)=False and (First_Harmful<>Pedestrian) =True) statement is False
Pedestrian ((First_Harmful<>Ped_~School)=True and (First_Harmful<>Pedestrian)=False) statement is False
Ped_~School and Pedestrian values would be filtered from the list of crashes.