Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

excel - How to combine 2 separate formulas based on additional criteria

I have 2 lines of code which both work well separately helping me to calculate staking, but I need to have both lines work in a single cell, but depending on additional criteria. For the life of me I haven't been able to get it to work Code 1

=IF(F19="","",IF(F19<3.5,L18*0.01,IF(F19<7.45,L18*0.006,IF(F19<11.1,L18*0.004,"0"))))

Code 2

=IF(F19="","",IF(F19<3.5,$M$18*0.01,IF(F19<7.45,$M$18*0.006,IF(F19<11.1,$M$18*0.004,"0"))))

What I need to try and do is have code 1 work IF L19>$M$18 and code 2 work IF L<=$M$18

I have tried many combinations of IF, AND and OR (over 2 hours so far), but can't seem to crack it. I keep getting "too many arguments" error messages

I haven't even been able to put just one side of the equation together with the required criteria

=IF(AND(F19="","",L19>$M$18,IF(F19<3.5,L18*0.01,IF(F19<7.45,L18*0.006,IF(F19<11.1,L18*0.004,"0")))))

If anyone can spot my obvious errors, I would appreciate your input

Thanks in advance

question from:https://stackoverflow.com/questions/66059665/how-to-combine-2-separate-formulas-based-on-additional-criteria

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

the too many arguments error is probably caused because you somehow entered 4 parameters inside an "IF" function instead of 3.

If I understand your question correctly, and need to put an extra condition in each code, try:

=IF(AND(F19="",L19>$M$18),"",IF(F19<3.5,L18*0.01,IF(F19<7.45,L18*0.006,IF(F19<11.1,L18*0.004,"0"))))

=IF(AND(F19="",L19<=$M$18),"",IF(F19<3.5,$M$18*0.01,IF(F19<7.45,$M$18*0.006,IF(F19<11.1,$M$18*0.004,"0"))))

But this seems too easy to fix, I probably misunderstood your requirements.

EDIT: OK, so you need one formula for these two

=IF(L19>$M$18, Code1, IF(L19<=$M$18, Code2, ""))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...