Sum_Sampled()

Format

Sum_Sampled(Expr ,StartTime [,EndTime])

Note: This function was named Accum in v2.6.

Returns

Returns the sum of the values of an expression over a range of time.

It is possible to retrieve very large volumes of data through indiscriminate use of this function. Retrieving large amounts of Historian data across a slow network can affect system performance for all users of the system.

Inputs

Expr: The expression whose values should be summed. Which values are summed will depend on how the expression is sampled.
Behaviour: Required
Dimension: Collection
Valid data types: Boolean, DateTime, Decimal, Integer, String, Duration

StartTime: The start time over which to produce the sum.
Behaviour: Required
Dimension: Collection, SingleValue
Valid data types: DateTime, Decimal, Integer, String

EndTime: The end time over which to produce the sum. If not specified, it assumes the current time.
Behaviour: Optional 
Dimension: Collection, SingleValue
Valid data types: DateTime, Decimal, Integer, String

How to format data types

Error Conditions

An error will be thrown if:

  • A tag or entity supplied as an argument does not exist.
  • The data type of a parameter is not valid.

Examples

Expression: Sum_Sampled(Expr, Time() - 60, Time())
Result: Sum over the last minute (60 seconds)

Expression: Sum_Sampled(Expr, Time() - 60)
Result: Sum over the last minute (60 seconds)

Expression: Sum_Sampled(Expr, Midnight(Time()))
Result: Sum since midnight (the start of the day)

Expression: Sum_Sampled({tag, sampleMethod = "Raw"}, Time() – 60)
Result: Sum of the raw values over the last minute

Expression: Sum_Sampled(Sampling(Expr, "raw"), Time() - 60)
Result: Sum of the raw values over the last minute

Related Functions

The following table illustrates the difference between the Sum_Sampled(), Sum(), and DDSum() functions. The following calculations were used to sum a row (Sum_Sampled) or column (Sum and DDSum):

Total Weekly Oil Production for a well:
Sum_Sampled({Well 1:Oil Production},"Monday","Friday")
Sum_Sampled({Well 2:Oil Production},"Monday","Friday")
Sum_Sampled({Well 3:Oil Production},"Tuesday","Friday")

Total Daily Oil Production for all online wells:
DDSum(DDGet("Hierarchy", 2, "Field1", ":Oil Production", "{[Well]:Status} == 'Online'", "Well"))
Sum({Well 1:Oil Production},{Well 2:Oil Production})
Sum({Well 1:Oil Production},{Well 2:Oil Production},{Well 3:Oil Production})

In this example, Well 3 did not exist before Tuesday, and the Sum() and Sum_Sampled() calculations will throw an error if an entity does not exist.

Entity/Attributes Timestamps    
      Monday** Tuesday Wednesday Thursday Friday Total Weekly Oil Production Using Sum_Sampled()^ Calc Used:
Field 1 Well 1 Production (bbl): 1 3 2 4 2 12 Sum_Sampled({Well 1:Oil Production},"Monday","Friday")
  Status: Online Offline Online Online Online  
Well 2 Production (bbl): 2 1 1 3 2 9 Sum_Sampled({Well 2:Oil Production},"Monday","Friday")
  Status: Online Online Offline Online Online  
Well 3* Production (bbl): DID NOT EXIST 2 1 2 2 7* Sum_Sampled({Well 3:Oil Production},"Tuesday","Friday")
  Status: Online Online Offline Online  
Total Daily Oil Production Using Sum()     3** 6 4 9 6    
      Sum({Well 1:Oil Production},{Well 2:Oil Production}) Sum({Well 1:Oil Production},{Well 2:Oil Production},{Well 3:Oil Production}) Sum({Well 1:Oil Production},{Well 2:Oil Production},{Well 3:Oil Production}) Sum({Well 1:Oil Production},{Well 2:Oil Production},{Well 3:Oil Production}) Sum({Well 1:Oil Production},{Well 2:Oil Production},{Well 3:Oil Production})    
Total Daily Oil Production Using DDSum()^
DDSum(DDGet("Hierarchy", 2, "Field1", ":Oil Production", "{[Well]:Status} == 'Online'", "Well"))
  Error: Well 3:Status doesn't exist 3 3 7 6    

Notes:

* For Well 3, the Sum_Sampled() calculation should not include Monday, because it did not exist then. It will throw an error if you try to evaluate Well 3 starting from Monday, but will return a value if you evaluate it from Tuesday.

** On Monday, the Sum() calculation should not include Well 3, because it did not exist then and will throw an error. Well 3 can only be included in the calculation from Tuesday onwards.

^ For an explanation of how the values for DDSum() and Sum() are calculated, refer to their respective pages.

 

Comments are closed