QlikView排序表达式匹配,内部带有IF表达式

时间:2019-06-12 09:22:46

标签: sorting qlikview qliksense qlik-expression

我正在尝试使用IF语句创建自定义排序表达式。

我有以下IF表达式:

=IF(VOTA >= -15 AND VOTA <= 15, '0',
IF(VOTA >= -60 AND VOTA <= -16, '-1 to 0',
IF(VOTA >= -120 AND VOTA <= -61, '-2 to -1',
IF(VOTA >= -180 AND VOTA <= -121, '-3 to -2',
IF(VOTA >= -240 AND VOTA <= -181, '-4 to -3',
IF(VOTA >= -241, '-4+',
IF(VOTA >= 60 AND VOTA <= 16, '1 to 0',
IF(VOTA >= 120 AND VOTA <= 61, '2 to 1',
IF(VOTA >= 180 AND VOTA <= 121, '3 to 2',
IF(VOTA >= 240 AND VOTA <= 181, '4 to 3',
IF(VOTA >= 241, '4+'
)))))))))))

将字段VOTA分组。

然后在排序表达式中,我这样做了:

=MATCH((IF(VOTA >= -15 AND VOTA <= 15, '0',
IF(VOTA >= -60 AND VOTA <= -16, '-1 to 0',
IF(VOTA >= -120 AND VOTA <= -61, '-2 to -1',
IF(VOTA >= -180 AND VOTA <= -121, '-3 to -2',
IF(VOTA >= -240 AND VOTA <= -181, '-4 to -3',
IF(VOTA >= -241, '-4+',
IF(VOTA >= 60 AND VOTA <= 16, '1 to 0',
IF(VOTA >= 120 AND VOTA <= 61, '2 to 1',
IF(VOTA >= 180 AND VOTA <= 121, '3 to 2',
IF(VOTA >= 240 AND VOTA <= 181, '4 to 3',
IF(VOTA >= 241, '4+'
)))))))))))), '-4+', '-4 to -3', '-3 to -2', '-2 to -1', '-1 to 0', '0', '1 to 0','2 to 1','3 to 2','4 to 3','4+')

但是它仍然没有按照要求进行排序。

1 个答案:

答案 0 :(得分:0)

我设法通过添加Dual('xx to xx', n)并对其进行数字排序来对其进行排序。

=IF(VOTA <= -241, Dual('-4+',-5),
IF(VOTA >= -240 AND VOTA <= -181, Dual('-3 to -4',-4),
IF(VOTA >= -180 AND VOTA <= -121, Dual('-2 to -3',-3),
IF(VOTA >= -120 AND VOTA <= -61, Dual('-1 to -2',-2),
IF(VOTA >= -60 AND VOTA <= -16, Dual('0 to -1',-1),
IF(VOTA >= -15 AND VOTA <= 15, Dual('0',0),
IF(VOTA <= 60 AND VOTA <= 16, Dual('0 to 1',1),
IF(VOTA <= 120 AND VOTA <= 61, Dual('1 to 2',2),
IF(VOTA <= 180 AND VOTA <= 121, Dual('2 to 3',3),
IF(VOTA <= 240 AND VOTA <= 181, Dual('3 to 4',4),
IF(VOTA >= 241, Dual('4+',5)
)))))))))))