Using LINEST function with conditions

Dave L

Board Regular
Joined
Jun 19, 2003
Messages
87
I have two columns of data (D & E) and the following equation works fine to calculate a straight line that best fits my data:

INDEX(LINEST($D$8:$D$18,$E&8:$E$18),2)

However, I need to calulate it only using data that meets a certain criteria (>=1). I tried the following, but got a "VALUE" error:

INDEX(LINEST(IF($D$8:$D$18>=1,$D$8:$D$18),IF($D$8:$D$18>=1,$E&8:$E$18)),2)

Any help would be greatly appreciated.

Thanks,

Dave
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Book2
CDEFGHIJ
607
7X1X2Idx*X1*X2
81.22.311.22.30.070983
922.9222.9
100.80.5 3.11
1107 1.71
123.11343
131.71421
1480 24
150.30.2   
16435  
17216  
18247  
19
Sheet1


Formulas...

F6 must house a 0.

F8, copied down:

=IF((D8>=1)*(E8>=1),LOOKUP(9.99999999999999E+307,$F$6:F7)+1,"")

G6:

=LOOKUP(9.99999999999999E+307,F6:F18)

G8, copied across to H8 then down:

=IF(ROWS(G$8:G8)<=$G$6,LOOKUP(ROWS(G$8:G8),$F$8:$F$18,D$8:D$18),"")

J8:

=LINEST(G8:INDEX(G8:G18,G6),H8:INDEX(H8:H18,G6))

Addendum:

=INDEX(LINEST(G8:INDEX(G8:G18,G6),H8:INDEX(H8:H18,G6)),2)
 
Upvote 0
Try the following...

F7: enter 0

F8, copied down:

=IF((D8<>"")*(E8<>""),IF(D8>=1,LOOKUP(9.99999999999999E+307,$F$7:F7)+1,""),"")

G7:

=LOOKUP(9.99999999999999E+307,F8:F18)

H8, copied down and over to Column I:

=IF(ROW()-ROW(H$8)+1<=$G$7,LOOKUP(ROW()-ROW(H$8)+1,$F$8:$F$18,D$8:D$18),"")

Define the following names...

Insert > Name > Define

Name: Array1

Refers to:

=Sheet1!$H$8:INDEX(Sheet1!$H$8:$H$18,Sheet1!$G$7)

Click Add

Name: Array2

Refers to:

=Sheet1!$I$8:INDEX(Sheet1!$I$8:$I$18,Sheet1!$G$7)

Click Ok

*Make sure that you change the sheet reference accordingly.

Then, use the following formula...

=INDEX(LINEST(Array1,Array2),2)

Hope this helps!

Edit: Changed the formulas for the defined names as per Aladin's solution. Nice!
 
Upvote 0
Dave,

I noticed that Aladin's solution eliminates any row where Column D or Column E does not contain a value greater than or equal to one. However, in your example, you only eliminate a row if Column D does not contain a value greater than or equal to one. My solution is based on your example. If, as I suspect, Aladin has it right, change my formula for F8 to the following...

=IF((D8<>"")*(E8<>""),IF((D8>=1)*(E8>=1),LOOKUP(9.99999999999999E+307,$F$7:F7)+1,""),"")
 
Upvote 0
How would you apply similar conditions to data that crosses thresholds. I want to include only the cells that have satisfied condition of n>30 threshold in the LINEST formula.

Ideally, I would have one array selected for the LINEST and I would not have to manually increase/decrease the cells used for the function as my column thresholds are crossed.

LINEST Example: Repair

=LINEST(C7:H7,$C$2:$H$2^{1;2},,TRUE)

<tbody>
</tbody>

50000100000150000200000250000300000350000400000
50k50-100k100-150k150-200k200-250k250-300k300-350k350-400k
Repair$1,198.54$1,054.26$1,352.07$1,767.28$1,271.92$1,722.23TOO FEWTOO FEW

<colgroup><col><col><col><col><col><col><col><col span="2"></colgroup><tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,216,160
Messages
6,129,215
Members
449,493
Latest member
JablesFTW

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