---
title: HKStatistics
framework: healthkit
role: symbol
role_heading: Class
path: healthkit/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.

## Declaration

```swift
class HKStatistics
```

## Overview

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 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 option, you must access the results using the averageQuantity() method. For more information on calculating statistical data, see HKStatisticsQuery Class Reference. To calculate the statistics over a series of time intervals, see the HKStatisticsCollectionQuery Class Reference.

## Topics

### Getting Property Data

- [startDate](healthkit/hkstatistics/startdate.md)
- [endDate](healthkit/hkstatistics/enddate.md)
- [quantityType](healthkit/hkstatistics/quantitytype.md)
- [sources](healthkit/hkstatistics/sources.md)

### Getting Statistics Data

- [averageQuantity()](healthkit/hkstatistics/averagequantity().md)
- [averageQuantity(for:)](healthkit/hkstatistics/averagequantity(for:).md)
- [maximumQuantity()](healthkit/hkstatistics/maximumquantity().md)
- [maximumQuantity(for:)](healthkit/hkstatistics/maximumquantity(for:).md)
- [minimumQuantity()](healthkit/hkstatistics/minimumquantity().md)
- [minimumQuantity(for:)](healthkit/hkstatistics/minimumquantity(for:).md)
- [sumQuantity()](healthkit/hkstatistics/sumquantity().md)
- [sumQuantity(for:)](healthkit/hkstatistics/sumquantity(for:).md)
- [duration()](healthkit/hkstatistics/duration().md)
- [duration(for:)](healthkit/hkstatistics/duration(for:).md)

### Getting the Most Recent Quantity

- [mostRecentQuantity()](healthkit/hkstatistics/mostrecentquantity().md)
- [mostRecentQuantity(for:)](healthkit/hkstatistics/mostrecentquantity(for:).md)
- [mostRecentQuantityDateInterval()](healthkit/hkstatistics/mostrecentquantitydateinterval().md)
- [mostRecentQuantityDateInterval(for:)](healthkit/hkstatistics/mostrecentquantitydateinterval(for:).md)

### Initializers

- [init(coder:)](healthkit/hkstatistics/init(coder:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Statistics

- [Executing Statistical Queries](healthkit/executing-statistical-queries.md)
- [Executing Statistics Collection Queries](healthkit/executing-statistics-collection-queries.md)
- [HKStatisticsQueryDescriptor](healthkit/hkstatisticsquerydescriptor.md)
- [HKStatisticsQuery](healthkit/hkstatisticsquery.md)
- [HKStatisticsCollectionQueryDescriptor](healthkit/hkstatisticscollectionquerydescriptor.md)
- [HKStatisticsCollectionQuery](healthkit/hkstatisticscollectionquery.md)
- [HKStatisticsCollection](healthkit/hkstatisticscollection.md)
- [HKStatisticsOptions](healthkit/hkstatisticsoptions.md)
