CORR

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Computes the correlation coefficient between two sets of values.

Syntax 

1corr(<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.

1SELECT corr(sales, advertising_spend) AS correlation
2FROM marketing_data;

Correlation by Group 

Calculate correlation for each category.

1SELECT category, corr(revenue, visitors) AS revenue_visitor_corr
2FROM store_metrics
3GROUP BY category;

Related Documentation