<!--
{
  "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/HKStatisticsOptions",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:@E@HKStatisticsOptions"
  },
  "title" : "HKStatisticsOptions"
}
-->

# HKStatisticsOptions

Options for specifying the statistic to calculate.

```
struct HKStatisticsOptions
```

## 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`](/documentation/HealthKit/HKStatisticsOptions/separateBySource) option with any of the other options.

## Swift

```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

```objc
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

[`HKStatisticsOptionNone`](/documentation/HealthKit/HKStatisticsOptions/HKStatisticsOptionNone)

An option indicating that the system will not calculate any statistics values.

[`HKStatisticsOptionSeparateBySource`](/documentation/HealthKit/HKStatisticsOptions/separateBySource)

An option indicating that the system calculates the specified statistics separately for each source.

[`HKStatisticsOptionDiscreteAverage`](/documentation/HealthKit/HKStatisticsOptions/discreteAverage)

An option indicating that the system calculates the average quantity for the samples.

[`HKStatisticsOptionDiscreteMin`](/documentation/HealthKit/HKStatisticsOptions/discreteMin)

An option indicating that the system calculates the minimum quantity for the samples.

[`HKStatisticsOptionDiscreteMax`](/documentation/HealthKit/HKStatisticsOptions/discreteMax)

An option indicating that the system calculates the maximum quantity for the samples.

[`HKStatisticsOptionCumulativeSum`](/documentation/HealthKit/HKStatisticsOptions/cumulativeSum)

An option indicating that the system calculates the sum of all the quantities for the samples.

[`HKStatisticsOptionMostRecent`](/documentation/HealthKit/HKStatisticsOptions/mostRecent)

An option indicating that the system returns the most recent quantity from the matching samples.

[`HKStatisticsOptionDuration`](/documentation/HealthKit/HKStatisticsOptions/duration)

An option indicating that the system calculates the total duration covering all the samples.

### Deprecated Constants

[`HKStatisticsOptionDiscreteMostRecent`](/documentation/HealthKit/HKStatisticsOptions/discreteMostRecent)

An option indicating that the system returns the most recent quantity from the matching samples.

### Initializers

[`init(rawValue:)`](/documentation/HealthKit/HKStatisticsOptions/init(rawValue:))

Returns a newly initialized statistics option using the provided integer.

## Relationships

### Conforms To

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

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

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

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

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

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

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

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

---

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)