一、需求内容
id | math | chinese | english | 综合 |
---|---|---|---|---|
1 | 60 | 78 | ||
2 | 67 | 89 | ||
3 | 90 | 79 | ||
4 | 79 | 68 | 80 | |
5 | 89 | |||
6 | 78 | |||
7 | 69 | |||
8 |
如上表所示,利用“math”,“chinese”,"english"三列进行计算,将结果写入“综合”列具体计算规则如下:综合等于去除空值后剩余科目的平均值,例如id=1的综合指应为(60+79)/2=69.5,id=6的综合值应为78,id=8值全为空则综合赋为0。
二、构建模型
第一步:加载数据
第二步:使用“填充”插件将数据各个列中为空的设置为0
第三步:使用“导出”插件,编写IF语句计算综合分,语句如下
if math+english+chinese=0 then 0
elseif math+chinese=0 then english
elseif chinese+english=0 then math
elseif math+english=0 then chinese
elseif math = 0 then (chinese+english)/2
elseif chinese = 0 then (math+english)/2
elseif english = 0 then (math+chinese)/2
else (math+english+chinese)/3
endif
注意:这里if语句是按照顺序进行匹配的,所以不同顺序得到的结果可能不一致。