**D****escription:**

This calculation computes the area under the curve for a function f(x), using the Trapezoid Rule for a non-uniform grid.

**Example Calculation:**

//The below calculation will compute the definite integral, over the whole domain, of f(x).

// If the current row is the first row, the area under the curve is zero.

IF FIRST()==0 THEN

0

ELSE

0.5*RUNNING_SUM((SUM([f(x)]) + LOOKUP(SUM([f(x)]), -1))*(SUM([x]) - LOOKUP(SUM([x]), -1)))

END

**Inputs and Setup: **

[x] - A numerical field

[f(x)] - Another numerical field.

- Each [x] value in the partition must correspond to a single [f(x)] value in the partition.

**Partitioning and Addressing:**

Compute using a field that partitions your data into the points in the view.

Alternately, if you wish to use all of the available points, you can turn off Aggregate Measures and compute using Table (Across).

**Comments:**

This calculation computes the definite integral of the function f(x).

The trapezoid rule can become unstable if there is a large change between consecutive [x] or [f(x)] values.

See the Trapezoid Rule Wikipedia Article for error analysis.

**Related Functions:**

**Notes:**

2013-03-20 Jonathan Drummey: optimized calc by changing LOOKUP(agg,0) to just agg, fixed potential error in IF statement if there were values of [x] that were the same as the first value of [x], also updated the attached workbook which is in Tableau version 8.

*Further Reading/Examples:*

## Comments