---
schema_version: "1"
id: ea299c125e598d67449cd99dfec3f2415f2d46f44985f2307e99c40becd97f3a
title: VARIANCE/VAR_SAMP
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/data-cloud/data-cloud-query-guide/references/data-cloud-sql-reference/aggregate-func/variance.md
canonical_url: https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/variance.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 61803f40d98ed07d0d42126974599099bef07281b50b8f11e786113c487ea3c8
products:
  - Data 360 Query Guide
  - Data 360 Developer Documentation
---
# `VARIANCE/VAR_SAMP`

**Applies to:** ✅ Data 360 SQL ✅ Tableau Hyper API

Computes the sample variance of input values.

## Syntax

```sql
variance(<expression>)
```

## Arguments

### Required

- `<expression>`: An expression of any numerical type.

## Returns

- `NUMERIC(38,6)` for integer-type or numeric arguments.
- `double precision` for floating-point arguments.

Returns NULL if the computation is meaningless.

## Considerations

- Uses N-1 in the denominator (Bessel's correction).
- Variance is the square of the standard deviation.
- Use `VAR_POP` for population variance.
- Cast the input to `double precision` to get a `double precision` result.

## Examples

### Calculate Variance

Find the variance of prices.

```sql
SELECT variance(price) AS price_variance
FROM products;
```

### Variance by Group

Calculate variance for each category.

```sql
SELECT category, variance(price) AS price_variance
FROM products
GROUP BY category;
```

## Related Documentation

- [VAR_POP](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/var-pop.md)
- [COVAR_SAMP/VAR_SAMP](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/covar-samp.md)
- [STDDEV](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/stddev.md)
- [Aggregate Functions](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/aggregate.md)
