Calculate Area Between 2 Lines on Excel

Sc0

New Member
Joined
Jul 12, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hey, I am not sure if this is the right place to ask but I cannot find anything that works for me so far. I have 2 lines on a chart in excel and the raw data for the 2 lines. The data is based on the X axis being the date and the Y axis being the price. There are 2 Y axis lines with my price for an item, and my sales price. I am tracking this over the past year for example and want to calculate the area between the 2 lines when I was selling below cost and selling above cost.

What is the easiest way to get this number?

Thanks,
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Did you fit lines to your data? Do you know the slopes and intercepts of the lines? If not, you can extract them with SLOPE and INTERCEPT. Then we know the equation of a line is y=mx+b and the area between the line and the x-axis is the integral of y with respect to x, or area = 0.5 * m * x^2 + b * x, evaluated between the x limits of interest. An example is shown below, two curves are shown, one for actual (A), the other for selling (S) price. They cross and we might be interested in knowing the area between the curves to the left of the intersection point (or somewhere close to it)...I've called that Section 1. We might also want the area to the right of this point...I've called that Section 2. So looking at the plot or the data table, the lower and upper dates for each section are input (G5:H6). The SLOPE and INTERCEPT formulas are used to extract slopes and intercepts for the two lines based on a linear regression of the data (see B2:C3). Then the areas between each line section and the x-axis are computed (A5:C6), and then to get the area between the two lines, the area associated with one line is subtracted from the area associated with the other. I've taken "positive" area to mean S>A, while negative area means A>S...see D5:E6.
MrExcel_20220805.xlsx
ABCDEFGH
1AS
2slope0.10703862-0.084177
3intercept-4671.61243874.839
4AreaArealower dateupper date
5section 116054.948617726.2981671.3494($-days)1/1/20226/1/2022
6section 214754.062112920.112-1833.95($-days)6/1/202210/1/2022
7
8DateActual CostSelling Price
91/1/2022100120
102/1/2022102120
113/1/2022104120
124/1/2022106118
135/1/2022110116
146/1/2022114113
157/1/2022118110
168/1/2022122106
179/1/2022124102
1810/1/202212898
Sheet3
Cell Formulas
RangeFormula
B2:C2B2=SLOPE(B9:B18,$A9:$A18)
B3:C3B3=INTERCEPT(B9:B18,$A9:$A18)
B5:C5B5=(0.5*B$2*$H$5^2+B$3*$H$5)-(0.5*B$2*$G$5^2+B$3*$G$5)
D5:D6D5=C5-B5
B6:C6B6=(0.5*B$2*$H$6^2+B$3*$H$6)-(0.5*B$2*$G$6^2+B$3*$G$6)

1659769841661.png
 
Upvote 0
Did you fit lines to your data? Do you know the slopes and intercepts of the lines? If not, you can extract them with SLOPE and INTERCEPT. Then we know the equation of a line is y=mx+b and the area between the line and the x-axis is the integral of y with respect to x, or area = 0.5 * m * x^2 + b * x, evaluated between the x limits of interest. An example is shown below, two curves are shown, one for actual (A), the other for selling (S) price. They cross and we might be interested in knowing the area between the curves to the left of the intersection point (or somewhere close to it)...I've called that Section 1. We might also want the area to the right of this point...I've called that Section 2. So looking at the plot or the data table, the lower and upper dates for each section are input (G5:H6). The SLOPE and INTERCEPT formulas are used to extract slopes and intercepts for the two lines based on a linear regression of the data (see B2:C3). Then the areas between each line section and the x-axis are computed (A5:C6), and then to get the area between the two lines, the area associated with one line is subtracted from the area associated with the other. I've taken "positive" area to mean S>A, while negative area means A>S...see D5:E6.
MrExcel_20220805.xlsx
ABCDEFGH
1AS
2slope0.10703862-0.084177
3intercept-4671.61243874.839
4AreaArealower dateupper date
5section 116054.948617726.2981671.3494($-days)1/1/20226/1/2022
6section 214754.062112920.112-1833.95($-days)6/1/202210/1/2022
7
8DateActual CostSelling Price
91/1/2022100120
102/1/2022102120
113/1/2022104120
124/1/2022106118
135/1/2022110116
146/1/2022114113
157/1/2022118110
168/1/2022122106
179/1/2022124102
1810/1/202212898
Sheet3
Cell Formulas
RangeFormula
B2:C2B2=SLOPE(B9:B18,$A9:$A18)
B3:C3B3=INTERCEPT(B9:B18,$A9:$A18)
B5:C5B5=(0.5*B$2*$H$5^2+B$3*$H$5)-(0.5*B$2*$G$5^2+B$3*$G$5)
D5:D6D5=C5-B5
B6:C6B6=(0.5*B$2*$H$6^2+B$3*$H$6)-(0.5*B$2*$G$6^2+B$3*$G$6)

View attachment 70971
Thanks I will try this later this week and let you know how it goes.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top