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

# HKStatistics

An object that represents the result of calculating the minimum, maximum, average, or sum over a set of samples from the HealthKit store.

```
class HKStatistics
```

## Overview

HealthKit creates statistic objects using either a statistics query or a statistics collection query. For the statistics query, it performs the specified calculations over all the samples that match the query. For the statistics collection query, it partitions the matching samples into a set of time intervals and performs the calculations over each interval separately.

By default, these queries automatically merge the data from all of your data sources before performing the calculations. If you want to merge the data yourself, you can set the [`separateBySource`](/documentation/HealthKit/HKStatisticsOptions/separateBySource) option. You can then request the statistical data for each source separately.

When requesting data from a statistics object, your request must match the options you used when creating the query. For example, if you create a query using the [`discreteAverage`](/documentation/HealthKit/HKStatisticsOptions/discreteAverage) option, you must access the results using the [`averageQuantity()`](/documentation/HealthKit/HKStatistics/averageQuantity()) method.

For more information on calculating statistical data, see [`HKStatisticsQuery`](/documentation/HealthKit/HKStatisticsQuery) Class Reference. To calculate the statistics over a series of time intervals, see the [`HKStatisticsCollectionQuery`](/documentation/HealthKit/HKStatisticsCollectionQuery) Class Reference.

## Topics

### Getting Property Data

[`startDate`](/documentation/HealthKit/HKStatistics/startDate)

The start of the time period included in these statistics.

[`endDate`](/documentation/HealthKit/HKStatistics/endDate)

The end of the time period included in these statistics.

[`quantityType`](/documentation/HealthKit/HKStatistics/quantityType)

The quantity type of the samples used to calculate these statistics.

[`sources`](/documentation/HealthKit/HKStatistics/sources)

An array containing all the sources contributing to these statistics.

### Getting Statistics Data

[`-  averageQuantity`](/documentation/HealthKit/HKStatistics/averageQuantity())

Returns the average value from all the samples that match the query.

[`-  averageQuantityForSource:`](/documentation/HealthKit/HKStatistics/averageQuantity(for:))

Returns the average value from all the samples that match the query and that were created by the specified source.

[`-  maximumQuantity`](/documentation/HealthKit/HKStatistics/maximumQuantity())

Returns the maximum value from all the samples that match the query.

[`-  maximumQuantityForSource:`](/documentation/HealthKit/HKStatistics/maximumQuantity(for:))

Returns the maximum value from all the samples that match the query and that were created by the specified source.

[`-  minimumQuantity`](/documentation/HealthKit/HKStatistics/minimumQuantity())

Returns the minimum value from all the samples that match the query.

[`-  minimumQuantityForSource:`](/documentation/HealthKit/HKStatistics/minimumQuantity(for:))

Returns the minimum value from all the samples that match the query and that were created by the specified source.

[`-  sumQuantity`](/documentation/HealthKit/HKStatistics/sumQuantity())

Returns the sum of all the samples that match the query.

[`-  sumQuantityForSource:`](/documentation/HealthKit/HKStatistics/sumQuantity(for:))

Returns the sum of all the samples that match the query and that were created by the specified source.

[`-  duration`](/documentation/HealthKit/HKStatistics/duration())

Returns the total duration covering all the samples that match the query.

[`-  durationForSource:`](/documentation/HealthKit/HKStatistics/duration(for:))

Returns the total duration covering all the samples created by the specified source that also match the query.

### Getting the Most Recent Quantity

[`-  mostRecentQuantity`](/documentation/HealthKit/HKStatistics/mostRecentQuantity())

Returns the most recent value from all the samples that match the query.

[`-  mostRecentQuantityForSource:`](/documentation/HealthKit/HKStatistics/mostRecentQuantity(for:))

Returns the most recent value from all the samples that match the query and were created by the specified source.

[`-  mostRecentQuantityDateInterval`](/documentation/HealthKit/HKStatistics/mostRecentQuantityDateInterval())

Returns the date interval of the most recent sample that matches the query.

[`-  mostRecentQuantityDateIntervalForSource:`](/documentation/HealthKit/HKStatistics/mostRecentQuantityDateInterval(for:))

Returns the date interval of the most recent sample that matches the query and was created by the specified source.

## Relationships

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

### Conforms To

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

[`NSCopying`](/documentation/Foundation/NSCopying)

[`NSCoding`](/documentation/Foundation/NSCoding)

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

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

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

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

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

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

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

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

---

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)