formula too long

d0wnt0wn

Well-known Member
Joined
Oct 28, 2002
Messages
771
hey guys... any way I can shorten this formula so I can use it. says I have too many conditions

=IF(E16>16,D16*1.8,IF(E16>14,D16*1.67,IF(E16>12,D16*1.54,IF(E16>11,D16*1.41,IF(E16>9,D16*1.3,IF(E16>7,D16*1.2,IF(E16>5,D16*1.12,IF(E16>4,D16*1.08,if(D16>3,D16*1.06,if(d16>2,d16*1.04,if(d16>1,d16*1.03,if(d16>0,d16*1.02,if(d16.-1,d16*1,)))))))))))))
 
hey guys... any way I can shorten this formula so I can use it. says I have too many conditions

=IF(E16>16,D16*1.8,IF(E16>14,D16*1.67,IF(E16>12,D16*1.54,IF(E16>11,D16*1.41,IF(E16>9,D16*1.3,IF(E16>7,D16*1.2,IF(E16>5,D16*1.12,IF(E16>4,D16*1.08,if(D16>3,D16*1.06,if(d16>2,d16*1.04,if(d16>1,d16*1.03,if(d16>0,d16*1.02,if(d16.-1,d16*1,)))))))))))))

. Hi
Wot version of Excel are you using? For excel 2007 and higher you can have up to 64 conditions, which I frerquently use.

. Maybe you have a typo in your last condition.
. The following formula, for example works fine for me in XL 2007

=IF(E16>16,D16,IF(E16>14,(D16*1.67),IF(E16>12,D16*1.54,IF(E16>11,D16*1.41,IF(E16>9,D16*1.3,IF(E16>7,D16*1.2,IF(E16>5,D16*1.12,IF(E16>4,D16*1.08,IF(D16>3,D16*1.06,IF(D16>2,D16*1.04,IF(D16>1,D16*1.03,IF(D16>0,D16*1.02,IF(D16>1.01,D16*1,)))))))))))))


.........
I am primarily a programmer, and I always prefer readability; your very long formula might also be easier for a human to read if split up.


. I am not a programmer, just learning VBA for private use. Long Formulas really confuse me. I fing it useful to copy the cell with the formula in it using the MrExcel Spreadsheet HTML Maker., (remembering to take the option all formulas). Then you can paste it in the test Forum where it comes up in colors which make long formulas a little bit more readable

Alan
 
Upvote 0
EDIT..

maybe this was the actual formula you wonted...
=IF(E16>16,D16,IF(E16>14,(D16*1.67),IF(E16>12,D16*1.54,IF(E16>11,D16*1.41,IF(E16>9,D16*1.3,IF(E16>7,D16*1.2,IF(E16>5,D16*1.12,IF(E16>4,D16*1.08,IF(D16>3,D16*1.06,IF(D16>2,D16*1.04,IF(D16>1,D16*1.03,IF(D16>0,D16*1.02,IF(D16>-1,D16*1,)))))))))))))

...but I think you get the point about the last condition...


yours is obviously syntaxly wrong I
f(d16.-1,d16*1,)
 
Upvote 0
d0wnt0wn,

Typically, a Lookup formula like =LOOKUP(E16,{0,1,2,3,4,5,7,9,11,12,14,16},{1.02,1.03,1.04,1.06,1.08,1.12,1.2,1.3,1.41,1.54,1.67,1.8}) can be used to return values from the second array based on trying to match E16 in the first array. The nature of Lookup is such that if for example the lookup value E16 is say 16.5 it will return a match based on the largest number smaller than 16.5. In this case that would be 16 and would therefore return 1.8 from the second array. A value of 15 would return 1.67 based on a nearest match with 14. This is essentially a way of returning values based on E16 being Greater Than or Equal To thelookup values in the first array.

Note that if E16 is equal to 16 it will match 16 and return 1.8 - which is not what you are wanting.

=LOOKUP(E16,{0,1,2,3,4,5,7,9,11,12,14,16}+10^-10,{1.02,1.03,1.04,1.06,1.08,1.12,1.2,1.3,1.41,1.54,1.67,1.8})

Because you wanted only Greater Than, I added the +10^-10 element as a modifier to the first array. 10 raised to the power negative 10 creates avery small fraction which hopefully is negligible compared to your actual values of E16 (?) Adding that small fraction to the values in first array means that typically, the value 16 becomes 16.0000000001

Now if E16 is equal to 16 it will not match with 16.0000000001 as it is larger in value than E16. It now matches with the nearest, smaller, non exact match, which is 14.0000000001 and therefore returns 1.67 as you would want.

If as I now understand, you want a multiplier of 1 if E16 = 0 and the other lookup multipliers for E16 values exceeding 0 then maybe this is the formula you need......

=IF(E16=0,D16,LOOKUP(E16,{0,1,2,3,4,5,7,9,11,12,14,16}+10^-10,{1.02,1.03,1.04,1.06,1.08,1.12,1.2,1.3,1.41,1.54,1.67,1.8})*D16)

I hope that makes sense and is of help?
 
Upvote 0
d0wnt0wn,

Typically, a Lo.....

I hope that makes sense and is of help?

Hi,

I found the description and nice use of colors informative

Alan

P.s. I think the OP is looking up half the values from E16 and the other half from D16. (Unless that is another typo)
 
Upvote 0
Hi,

I found the description and nice use of colors informative

Alan

P.s. I think the OP is looking up half the values from E16 and the other half from D16. (Unless that is another typo)

Alan, I'm glad I appeared to make sense, for once ;)

Post #1 certainly suggested that the lookup was half E16 and half D16 but then the formula breakdown in post #3 referenced E16 for all which did make me assume that post #1 was a typo.

Perhaps d0wnt0wn will confirm.
 
Upvote 0
Morning All,

I still think you can use the Choose function when you have a relatively constrained list of choices. I accept that if the bounds grew much above the list provided it would be too cumbersome and the Lookup option provides a more flexible approach. Horses for courses, but sometimes simplistic can be effective.

Just a thought.
 
Upvote 0
.. Guten morgen All

......
Post #1 certainly suggested that the lookup was half E16 and half D16 but then the formula breakdown in post #3 referenced E16 for all which did make me assume that post #1 was a typo........

.... oops I overlooked that...:oops:
 
Upvote 0
Morning All,

I still think you can use the Choose function when you have a relatively constrained list of choices. I accept that if the bounds grew much above the list provided it would be too cumbersome and the Lookup option provides a more flexible approach. Horses for courses, but sometimes simplistic can be effective.

Just a thought.

Peter,

If the bounds grew much above the list provided, my LOOKUP formula would also start to become somewhat cumbersome.

Regards using the CHOOSE......
If you test your posted choose formula I think you will find that it doesn't quite work. In part that is because choose will return #Value! error if the index number is < 1 or > than the last value in the list. Also if the Index number is not an integer then Choose truncates to the lowest integer.

Other than I have made no provision for dealing with negative E16 (Applies equally to my Lookup formula!) this CHOOSE formula should work...

=CHOOSE(MIN(ROUNDUP(E16,)+1,18), 1, 1.02, 1.03, 1.04, 1.06, 1.08, 1.12, 1.12, 1.2, 1.2, 1.3,1.3, 1.41, 1.54, 1.54, 1.67, 1.67,1.8)*D16
 
Upvote 0
Guten Abend,
. While I was going through experimenting and learning from this Thread I came up along the way with another Formula alternative that works. It is more messy than the others but I thought just for completeness I would post it:

=VLOOKUP(E16,{-1.000001,1;0.000001,1.02;1.0000001,1.03;2.000000001,1.04;3.000000001,1.06;4.000000001,1.08;5.000000001,1.12;7.000000001, 1.2;9.000000001,1.3;11.000000001,1.41;12.000000001,1.54;12.000000001,1.54;14.000000001,1.67;16.000000001,1.8},2)

Just in case anyone wants to play with that or the other formulas I have them again in this spreadsheet (XL 2007)
https://app.box.com/s/itpnrwsxn3qu1iw894uq

Alan

 
Upvote 0

Forum statistics

Threads
1,226,799
Messages
6,193,067
Members
453,773
Latest member
bclever07

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