---
title: HKStatisticsQueryDescriptor
framework: healthkit
role: symbol
role_heading: Structure
path: healthkit/hkstatisticsquerydescriptor
---

# HKStatisticsQueryDescriptor

A query descriptor that calculates the minimum, maximum, average, or sum over a set of samples from the HealthKit store.

## Declaration

```swift
struct HKStatisticsQueryDescriptor
```

## Mentioned in

Reading data from HealthKit

## Overview

Overview Use the HKStatisticsQueryDescriptor to perform calculations over sets of samples currently saved in the HealthKit store. // Create a predicate for today's samples. let calendar = Calendar(identifier: .gregorian) let startDate = calendar.startOfDay(for: Date()) let endDate = calendar.date(byAdding: .day, value: 1, to: startDate) let today = HKQuery.predicateForSamples(withStart: startDate, end: endDate)

// Create the query descriptor. let stepType = HKQuantityType(.stepCount) let stepsToday = HKSamplePredicate.quantitySample(type: stepType, predicate:today) let sumOfStepsQuery = HKStatisticsQueryDescriptor(predicate: stepsToday, options: .cumulativeSum)

// Run the query. let stepCount = try await sumOfStepsQuery.result(for: store)?     .sumQuantity()?     .doubleValue(for: HKUnit.count())

// Use the step count here.

## Topics

### Creating Query Descriptors

- [init(predicate:options:)](healthkit/hkstatisticsquerydescriptor/init(predicate:options:).md)

### Running Queries

- [result(for:)](healthkit/hkstatisticsquerydescriptor/result(for:).md)

### Accessing Query Properties

- [predicate](healthkit/hkstatisticsquerydescriptor/predicate.md)
- [options](healthkit/hkstatisticsquerydescriptor/options.md)

### Default Implementations

- [HKAsyncQuery Implementations](healthkit/hkstatisticsquerydescriptor/hkasyncquery-implementations.md)

## Relationships

### Conforms To

- [Copyable](swift/copyable.md)
- [Escapable](swift/escapable.md)
- [HKAsyncQuery](healthkit/hkasyncquery.md)

## See Also

### Statistics

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