Hi,

I am trying to calculate area under the curve (auc). For some reason my formula doesn’t work. I don’t understand why. I would be grateful for your help.

# Need help with formula

Here’s the correct formula:

`((int.t2-int.t1)*(thisRow.x1i+thisRow.x2i)+(int.t3-int.t2)*(thisRow.x2i+thisRow.x3i)+(int.t4-int.t3)*(thisRow.x3i+thisRow.x4i)+(int.t5-int.t4)*(thisRow.x4i+thisRow.x5i))/2`

First of all, instead of `ip.x1i`

, `ip.x2i`

etc you should use `thisRow.x1i`

or just `x1i`

— because if you explicitly specify table name, it returns a list of values from all rows, not from current row only.

Secondly, you had a problem with division — you need to divide the sum of all products by 2, not only the last product. Each trapezoid’s area formula is `width * (height1 + height2) / 2`

3 Likes