MS Excel:根据条件生成一个值
我正在尝试制作一个Excel工作表。 其中,我想把12对条件。 这意味着,我想给两个值,并根据它们,它会产生一个输出。
例如:
a1< 50 and b1<5 then it should print 100 a1>= 50 and a1<100 and b1<5 then it should print 200 a1>= 100 and a1<200 and b1<5 then it should print 300 a1>= 200 and a1<500 and b1<5 then it should print 400
我试过这个:
=if(AND(A1<=75,B1<=5),1.341,AND(A1>=76,B1<=5,A1<=150),1.341,AND(A1>=151,A1<=350,B1<=5),1.408,AND(A1>350,B1<=5),1.475)
但是这是说我已经input了太多的这个函数的参数。
有谁知道我要去哪里错了?
IF
只接受3个参数:( (condition, value if condition is true, value if condition is false)
。
所以你可以使用嵌套的IF
s:
=IF(AND(A1<50,B1<5),100,IF(AND(A1>=50,A1<100,B1<5),200,IF(.........)))
但是这样做可能会更简单:
=IF(B1<5,100*(A1<50)+200*AND(A1>=50,A1<100)+300*AND(A1>=100,A1<200)+400*AND(A1>=200,A1<500),"")
这第二种方法工作,因为TRUE
评估为1和FALSE
为0。
一种方法是嵌套IFs:
=IF( condition1, value1, IF( condition2, value2, valueDefault ) ).
但是这可能变得非常复杂。 在两个variables(a和b)的情况下,更透明的解决scheme是创build一个查找表:第一列包含50,100和200,第一行包含5,100,200,500,而表的其余部分充满了价值观,然后你可以写一些像:
=INDEX( values, MATCH( actualA, firstColumn, 1 ), MATCH( actualB, firstRow, 1 ) )