---
title: "averageQuantity(for:)"
framework: healthkit
role: symbol
role_heading: Instance Method
path: "healthkit/hkstatistics/averagequantity(for:)"
---

# averageQuantity(for:)

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

## Declaration

```swift
func averageQuantity(for source: HKSource) -> HKQuantity?
```

## Parameters

- `source`: A data source from the statistics object’s doc://com.apple.healthkit/documentation/HealthKit/HKStatistics/sources array.

## Return Value

Return Value If both the discreteAverage option and the separateBySource option were set, this method returns a quantity object. This object contains the average value from all the samples that match the query and that were created by the specified source. If the statistics options were not both set, this method returns nil

## See Also

### Related Documentation

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

### Getting Statistics Data

- [averageQuantity()](healthkit/hkstatistics/averagequantity().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)
