# `CORR`

**Applies to:** ✅ Data 360 SQL ✅ Tableau Hyper API

Computes the correlation coefficient between two sets of values.

## Syntax

```sql
corr(<Y>, <X>)
```

## Arguments

### Required

- `<Y>`: A `double precision` expression representing the dependent variable.
- `<X>`: A `double precision` expression representing the independent variable.

## Returns

Returns a `double precision` value representing the correlation coefficient, ranging from -1 to 1. Returns NULL if the computation is meaningless (e.g., no valid input pairs).

## Considerations

- Returns NULL if there are no rows where both X and Y are non-null.
- A value of 1 indicates perfect positive correlation.
- A value of -1 indicates perfect negative correlation.
- A value of 0 indicates no linear correlation.

## Examples

### Calculate Correlation

Find the correlation between two variables.

```sql
SELECT corr(sales, advertising_spend) AS correlation
FROM marketing_data;
```

### Correlation by Group

Calculate correlation for each category.

```sql
SELECT category, corr(revenue, visitors) AS revenue_visitor_corr
FROM store_metrics
GROUP BY category;
```

## Related Documentation

- [COVAR_POP](/docs/data/data-cloud-query-guide/references/dc-sql-reference/covar-pop.md)
- [COVAR_SAMP](/docs/data/data-cloud-query-guide/references/dc-sql-reference/covar-samp.md)
- [Aggregate Functions](/docs/data/data-cloud-query-guide/references/dc-sql-reference/aggregate.md)
