USEMASTERFIELDTIME
The USEMASTERFIELDTIME query modifier is used only for the MultiField tags. It returns the value of all the fields at the same timestamp of the master field time, in each interval returned.
The following are the points to remember while using the USEMASTERFIELDTIME query modifier:
- In your user defined data type, you have to indicate which field is the master field. You can define a master field when you define the type.
- When you use the USEMASTERFIELDTIME query modifier, the query returns raw values of all the field elements at the timestamp determined by the MasterField.
- When you use the USEMASTERFIELDTIME query modifier in Excel Add-in, the percentage good value displayed will be incorrect. It is recommended to use this query modifier using APIs.
- Only a few calculation modes are supported by the USEMASTERFIELDTIME query modifier. The supported calculation modes are:
- Minimum Value
- Maximum Value
- Minimum Time
- Maximum Time
- FirstRawValue
- FirstRawTime
- LastRawValue
- LastRawTime
The supported modes will examine the raw samples for the master field of a Multi Field tag. For each raw sample in the interval, the minimum or maximum or first or last sample is determined depending on the mode. The timestamp of that raw sample is the master field time.
For example you have a multi-field tag called mytag
with 3 fields and field3 is the master field.
- You do a LastRawValue query on
mytag
and pass the USEMASTERFIELDTIME query modifier. - The Data Archiver determines the last raw sample for mytag.field3 between 3pm and 4pm is at 3:42pm. That is the master field time for this interval. Each interval has a master field time.
- The Data Archiver gets the values for field1 and field2 at 3:42 so now you have a value for all 3 fields at 3:42.
- Example
-
Import this data to demonstrate the behavior of the USEMASTERFIELDTIME query modifier.
[Data] Tagname,TimeStamp,Value,DataQuality MUser1.F1,05-22-2013 14:15:00,4,Good MUser1.F1,05-22-2013 14:15:01,7,Good MUser1.F1,05-22-2013 14:15:02,9,Good MUser1.F2,05-22-2013 14:15:00,241,Good MUser1.F2,05-22-2013 14:15:01,171,Good MUser1.F2,05-22-2013 14:15:02,191,Good
Note: In this sample the MUser1 tag has two fields F1 and F2 and F2 is marked as the MasterField.Run the following query:
set starttime = '5/22/2013 14:15:00', endtime = '5/22/2013 14:15:02' select tagname, timestamp, value, quality from ihrawdata where tagname = 'MUser1' and samplingmode = calculated and calculationmode = minimum and criteriastring = '#USEMASTERFIELDTIME' and numberofsamples = 1
The output is as follows:
Tag Name Time Stamp Value Quality MUser1.F1 05-22-201314:15:02 7 0.0000000 MUser1.F2 05-22-201314:15:02 171.000000000000 100.0000000 Here the minimum value for the Master Field tag F2 is 171 at 14:15:01 timestamp. That is the master time. Then the master time is used to get the value of F1 at the same timestamp which is 7 and this is returned even as the minimum value of F1 is 4.
In a multi field tag it is possible that some fields may be NULL at a given timestamp. In this case if F1 was a NULL value at 14:15:01 you would get a value of null and bad quality.