ONLYGOOD

The ONLYGOOD modifier excludes bad and uncertain data quality values from retrieval and calculations. Use this modifier with any sampling or calculation mode but it is most useful with Raw and CurrentValue queries.

All the calculation modes such as minimum or average exclude bad values by default, so this modifier is not required with those.

Example 1:Demonstrating the Behavior

Import the following data to demonstrate the behavior of ONLYGOOD

[Tags]
Tagname,DataType,HiEngineeringUnits,LoEngineeringUnits
BADDQTAG,SingleFloat,60,0
[Data]
Tagname,TimeStamp,Value, DataQuality
BADDQTAG,12-Jul-2012 8:59:00.000,22.7,Good
BADDQTAG,12-Jul-2012 9:08:00.000,12.5,Bad
BADDQTAG,12-Jul-2012 9:14:00.000,7.0,Bad
BADDQTAG,12-Jul-2012 9:22:00.000,4.8,Good
Example 2: Excluding bad data from raw data query

Without any query modifier, all raw samples are returned from a RawByTime query.

select timestamp,value,quality 
from ihrawdata
where tagname = BADDQTAG and samplingmode=Rawbytime and timestamp < now
Time StampValueQuality
7/12/2012 08:59:00 22.7000000Good, NonSpecific
7/12/201209:08:0012.5000000Bad, NonSpecific
7/12/201209:14:007.0000000Bad, NonSpecific
7/12/201209:22:004.8000000Good, NonSpecific
Note: The above results have both good and bad samples:

Now by using the ONLYGOOD modifier, you can exclude the bad quality values:

select timestamp,value,quality 
from ihrawdata
where tagname = BADDQTAG and samplingmode=Rawbytime and timestamp < now and criteriastring="#ONLYGOOD" 
timestamp             value              quality
Time StampValueQuality
7/12/2012 08:59:00 22.7000000Good, NonSpecific
7/12/201209:22:004.8000000Good, NonSpecific
Note: Only the good samples have been retrieved.
Example 3: Retrieving the last known value
Value

You can use the ONLYGOOD query modifier to show the last known good value for a tag. If the collector loses communication with the data source or has shut down, you can ignore the bad data that is logged.

The following examples demonstrate the ways to retrieve the last known values:

[Tags]
Tagname,DataType,HiEngineeringUnits,LoEngineeringUnit
CURRENTLYBAD,SingleInteger,60,0
[Data]
Tagname,TimeStamp,Value,DataQuality
CURRENTLYBAD,06-Aug-2012 8:59:00.000,2,Good
CURRENTLYBAD,06-Aug-2012 9:02:00.000,0,Bad

Without any query modifier, the newest raw sample is returned in a current value query as retrieved with the following query.

select timestamp,value,quality 
from ihrawdata
where tagname = CURRENTLYBAD and samplingmode=CurrentValue
Time StampValueQuality
8/6/201209:02:00BadNonSpecific

The bad data could be a communication error or collector shutdown marker

When the ONLYGOOD modifier is used, the bad quality value is ignored and last known good value is returned as per the query here.

select timestamp,value,quality 
from ihrawdata
where tagname = CURRENTLYBAD and samplingmode=CurrentValue and criteriastring="#ONLYGOOD"
Note: only the Good value has been retrieved as following. timestamp value quality.
Time StampValueQuality
8/6/201208:59:00 2 Good NonSpecific
Anticipated Usage

You can use the ONLYGOOD modifier to exclude end of collection markers but understand that it excludes all bad data, even communication errors, and out of range errors.

If you want to bring data into Microsoft Excel for further analysis, you can use ONLYGOOD so that good values are brought into a spreadsheet.