---
title: HKStatisticsOptions
framework: healthkit
role: symbol
role_heading: Structure
path: healthkit/hkstatisticsoptions
---

# HKStatisticsOptions

Options for specifying the statistic to calculate.

## Declaration

```swift
struct HKStatisticsOptions
```

## Overview

Overview You cannot combine a discrete option with a cumulative option. You can, however, combine multiple discrete options together to perform multiple calculations. You can also combine the separateBySource option with any of the other options. Swift let cumulativeActiveEnergyBurned = HKQuantityType(.activeEnergyBurned)   let discreteHeartRate = HKQuantityType(.heartRate)   // Cannot combine cumulative options with discrete options. // However, you can combine a cumulative option and separated by source let cumulativeQuery = HKStatisticsQuery(quantityType:cumulativeActiveEnergyBurned,                                         quantitySamplePredicate:nil,                                         options: [.cumulativeSum, .separateBySource]) {                                             query, statistics, error in                                                                                          // ... process the results here }   // You can also combine any number of discrete options // and the separated by source option. let discreteQuery = HKStatisticsQuery(quantityType: discreteHeartRate,                                       quantitySamplePredicate: nil,                                       options: [.discreteAverage, .discreteMin, .discreteMax, .separateBySource]) {                                             query, statistics, error in                                                                                          // ... process the results here } Objective-C HKQuantityType *cumulativeActiveEnergyBurned = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierActiveEnergyBurned];   HKQuantityType *discreteHeartRate = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate];   // Cannot combine cumulative options with discrete options. // However, you can combine a cumulative option and seperated by source HKStatisticsQuery *cumulativeQuery = [[HKStatisticsQuery alloc]  initWithQuantityType:cumulativeActiveEnergyBurned  quantitySamplePredicate:nil  options:HKStatisticsOptionCumulativeSum | HKStatisticsOptionSeparateBySource  completionHandler:^(HKStatisticsQuery *query, HKStatistics *result, NSError *error) {         // ... process the results here  }];   // You can also combine any number of discrete options // and the seperated by source option. HKStatisticsQuery *discreteQuery = [[HKStatisticsQuery alloc]  initWithQuantityType:discreteHeartRate  quantitySamplePredicate:nil  options:HKStatisticsOptionDiscreteAverage | HKStatisticsOptionDiscreteMin |  HKStatisticsOptionDiscreteMax | HKStatisticsOptionSeparateBySource  completionHandler:^(HKStatisticsQuery *query, HKStatistics *result, NSError *error) {        // ... process the results here  }];

## Topics

### Constants

- [separateBySource](healthkit/hkstatisticsoptions/separatebysource.md)
- [discreteAverage](healthkit/hkstatisticsoptions/discreteaverage.md)
- [discreteMin](healthkit/hkstatisticsoptions/discretemin.md)
- [discreteMax](healthkit/hkstatisticsoptions/discretemax.md)
- [cumulativeSum](healthkit/hkstatisticsoptions/cumulativesum.md)
- [mostRecent](healthkit/hkstatisticsoptions/mostrecent.md)
- [duration](healthkit/hkstatisticsoptions/duration.md)

### Deprecated Constants

- [discreteMostRecent](healthkit/hkstatisticsoptions/discretemostrecent.md)

### Initializers

- [init(rawValue:)](healthkit/hkstatisticsoptions/init(rawvalue:).md)

## Relationships

### Conforms To

- [BitwiseCopyable](swift/bitwisecopyable.md)
- [Equatable](swift/equatable.md)
- [ExpressibleByArrayLiteral](swift/expressiblebyarrayliteral.md)
- [OptionSet](swift/optionset.md)
- [RawRepresentable](swift/rawrepresentable.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
- [SetAlgebra](swift/setalgebra.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)
- [HKStatistics](healthkit/hkstatistics.md)
- [HKStatisticsCollection](healthkit/hkstatisticscollection.md)
