AFSearch.Aggregate Method
- Last UpdatedJan 12, 2026
- 3 minute read
- PI System
- AF SDK 3.2.0
- Developer
Performs all requested aggregates on the objects that match the search criteria.
Namespace: OSIsoft.AF.Search
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.2.0.7
Syntax
public AFAggregateResultCollection Aggregate( IEnumerable<AFAggregateRequest> aggregateRequests )
Public Function Aggregate ( aggregateRequests As IEnumerable(Of AFAggregateRequest) ) As AFAggregateResultCollection Dim instance As AFSearch Dim aggregateRequests As IEnumerable(Of AFAggregateRequest) Dim returnValue As AFAggregateResultCollection returnValue = instance.Aggregate(aggregateRequests)
public: AFAggregateResultCollection^ Aggregate( IEnumerable<AFAggregateRequest^>^ aggregateRequests )
member Aggregate : aggregateRequests : IEnumerable<AFAggregateRequest> -> AFAggregateResultCollection
Parameters
- aggregateRequests
- Type: System.Collections.GenericIEnumerableAFAggregateRequest
All aggregates that should be performed on the search results.
Return Value
Type: AFAggregateResultCollectionAn AFAggregateResultCollection containing the results of the requested aggregates or errors if the aggregates could not be performed.
Examples
// Get the Database PISystems myPISystems = new PISystems(); PISystem myPISystem = myPISystems.DefaultPISystem; if (myPISystem == null) throw new InvalidOperationException("Default PISystem was not found."); AFDatabase myDB = myPISystem.Databases[dbName]; if (myDB == null) throw new InvalidOperationException("Database was not found."); // Create a search to find all the event frames created from the 'Event' // template in the last year. using (AFEventFrameSearch eventSearch = new AFEventFrameSearch(myDB, "EventFrameSearch", @"Template:'Event' Start:>'t-1y'")) { eventSearch.CacheTimeout = TimeSpan.FromMinutes(10); // Get several aggregates in one call var averageAndCount = new AFSummaryRequest("Duration", AFSummaryTypes.Average | AFSummaryTypes.Count); var binByMonth = averageAndCount.BinBy("StartTime", new AFTimeSpan(months: 1).GetIntervalTimes(new AFTimeRange("1-1y", "1+1mo"))); var groupByElement = averageAndCount.GroupBy("Element"); var overallSummaries = new AFSummaryRequest("Duration", AFSummaryTypes.Minimum | AFSummaryTypes.Average | AFSummaryTypes.Maximum); var aggregateResults = eventSearch.Aggregate(new AFAggregateRequest[] { binByMonth, groupByElement, overallSummaries }); var overallSummaryResult = aggregateResults.GetResult(overallSummaries); Console.WriteLine("Minimum: {0}, Average: {1}, Maximum: {2}", overallSummaryResult.SummaryResults[AFSummaryTypes.Minimum], overallSummaryResult.SummaryResults[AFSummaryTypes.Average], overallSummaryResult.SummaryResults[AFSummaryTypes.Maximum]); var binByMonthResult = aggregateResults.GetResult(binByMonth); foreach (var bin in binByMonthResult.BinnedResults) { Console.WriteLine("Month: {0}, Average: {1}, Count: {2}", bin.Key, bin.Value[AFSummaryTypes.Average], bin.Value[AFSummaryTypes.Count]); } var groupByElementResult = aggregateResults.GetResult(groupByElement); foreach (var group in groupByElementResult.GroupedResults) { Console.WriteLine("Element: {0}, Average: {1}, Count: {2}", group.Key, group.Value[AFSummaryTypes.Average], group.Value[AFSummaryTypes.Count]); } }