---
schema_version: "1"
id: 0c4c3f4fb813b35dd6707fe5561f4f3858fee14847a166c9d13959032cf2e780
title: regr_r2()
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_saql/guides/concept/bi-saql-fn-agg-regr2.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-fn-agg-regr2.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 70ff5e25e0486277e93e4f39f09e1eda5be4d813657e1fa185eab9470c522bed
products:
  - Analytics SAQL Developer Guide
  - analytics
---

# regr_r2()

Uses two numerical fields to calculate R-squared, or goodness of fit. Use `regr_r2()` to understand how well the trend line fits your data.

```nolang
regr_r2(field_y, field_x)
```

_field_y_ is a grouped dependent numeric expression and _field_x_ is a grouped independent numeric expression. `regr_r2(field_y, field_x)` uses simple linear regression to calculate a trend line, then calculates R-squared. If the returned value is small, then functions like `regr_slope()` and `regr_intercept()` are likely to return accurate results.

The input fields (_field_y_, _field_x_) must contain at least two pairs of non-null values. This function works with simple grouped values but not with cogroups.

## Example - How Well Does the Calculated Trend Line Fit My Data

Suppose that you have a dataset that includes the number of activities (such as meetings) and the won opportunity amount.

![Sample scatter plot.](https://developer.salesforce.com/media/bi_dev_guide_saql/bi_saql_fn_agg_regint.png)

You want to check the calculated trend line for 'goodness of fit' to see how accurate the results from other statistical functions are.

```nolang
q = load "regression";
q = group q by all;

q = foreach q generate trunc(regr_r2('Amount', 'NumActivities'),2) as 'R Squared';
```

The value of R squared is 0.95.

![Diagram showing R squared result.](https://developer.salesforce.com/media/bi_dev_guide_saql/bi_saql_fn_agg_r2.png)
