<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKStatisticsCollectionQuery",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKStatisticsCollectionQuery"
  },
  "title" : "HKStatisticsCollectionQuery"
}
-->

# HKStatisticsCollectionQuery

A query that performs multiple statistics queries over a series of fixed-length time intervals.

```
class HKStatisticsCollectionQuery
```

## Overview

Statistics collection queries are often used to produce data for graphs and charts. For example, you might create a statistics collection query that calculates the total number of steps for each day or the average heart rate for each hour. Like observer queries, collection queries can also act as long-running queries, receiving updates when the HealthKit store’s content changes.

> Important:
> You can only use statistics collection queries with quantity samples. If you want to calculate statistics over workouts or correlation samples, you must perform the appropriate query and process the data yourself.

Statistics collection queries are mostly immutable. You can assign the query’s [`initialResultsHandler`](/documentation/HealthKit/HKStatisticsCollectionQuery/initialResultsHandler) and [`statisticsUpdateHandler`](/documentation/HealthKit/HKStatisticsCollectionQuery/statisticsUpdateHandler) properties after instantiating the object. You must set all other properties when you instantiate the object, and they can’t change.

For more information about statistics queries, see [`HKStatisticsQuery`](/documentation/HealthKit/HKStatisticsQuery).

## Topics

### Creating Statistics Collection Objects

  <doc://com.apple.healthkit/documentation/HealthKit/executing-statistics-collection-queries>

[`-  initWithQuantityType:quantitySamplePredicate:options:anchorDate:intervalComponents:`](/documentation/HealthKit/HKStatisticsCollectionQuery/init(quantityType:quantitySamplePredicate:options:anchorDate:intervalComponents:))

Initializes a statistics collection query to perform the specified calculations over a set of time intervals.

### Getting and Setting Results Handlers

[`initialResultsHandler`](/documentation/HealthKit/HKStatisticsCollectionQuery/initialResultsHandler)

The results handler for the query’s initial results.

[`statisticsUpdateHandler`](/documentation/HealthKit/HKStatisticsCollectionQuery/statisticsUpdateHandler)

The results handler for monitoring updates to the HealthKit store.

### Getting Property Data

[`anchorDate`](/documentation/HealthKit/HKStatisticsCollectionQuery/anchorDate)

The anchor date for the collection’s time intervals.

[`intervalComponents`](/documentation/HealthKit/HKStatisticsCollectionQuery/intervalComponents)

The date components that define the time interval for each statistics object in the collection.

[`options`](/documentation/HealthKit/HKStatisticsCollectionQuery/options)

A list of options that define the type of statistical calculations performed and the way in which data from multiple sources are merged.

## Relationships

### Conforms To

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Hashable`](/documentation/Swift/Hashable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Sendable`](/documentation/Swift/Sendable)

[`Equatable`](/documentation/Swift/Equatable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

### Inherits From

[`HKQuery`](/documentation/HealthKit/HKQuery)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)