Excel - 具有2个变量的多个条件

问题描述 投票:0回答:2

我正在研究一个excel数据集,我有两个变量 -

1)一次花费

2)分期支出。

现在,这两个变量下的观察包含4种可能性。

A - 一次花费> 0,分期花费= 0

B - 一次支出= 0,分期支出> 0

C - 一次消费= 0,分期支出= 0

D - 一次花费> 0,分期花费> 0。

我想创建一个名为Spend type的新变量,它可以基于对Spend进行分类

A-Onetime花费,

B-Installment花费,

C-No Spend,

D-Both一次性和分期付款。

任何人都可以帮我在excel中创建这个新变量吗?

enter image description here

excel if-statement conditional
2个回答
0
投票

你的意思是公式吗?在空单元格的情况下,我添加了无效类别。

=IF(OR(ISBLANK(A2),ISBLANK(B2)),"invalid",IF(AND(A2=0,B2=0),"No spend",IF(AND(A2>0,B2>0),"Both",IF(AND(A2=0,B2>0),"Installment spend","One time spend"))))

Spreadsheet


0
投票

这是一个略有不同的公式方法:

=INDEX({"No Spend","Onetime Spend","Installment Spend","Both One time and Installment"},MATCH((A2>0)+(B2>0)*2,{0,1,2,3},0))

enter image description here


或者这个较短的版本:

=CHOOSE((A2>0)+(B2>0)*2+1,"No Spend","Onetime Spend","Installment Spend","Both One time and Installment")

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.