首页 > 解决方案 > 在 Spotfire 表中排名、分组和设置标签

问题描述

我有两列 [Clients] 和 [Sales],我想创建一个新列,其中包含每个“客户”在销售额方面的评分(从 1 到 5)。我想对 [Sales] 进行排名并将其分成 5 组,然后将标签 1 设置为最高 [Sales],2 设置为第二组,依此类推……有人知道表达方式吗?利用 ?

标签: spotfiretibco

解决方案


您可以将 percentile 函数与 case 语句结合使用。在下面的屏幕截图中,我创建了 5 个计算来找到第 20、第 40、第 60 和第 80 个百分位数,然后创建了一个案例陈述以根据这些值进行排名。

百分位数计算:

Percentile([Sales],20)

案例陈述:

case  
when [Sales]<[20th Percentile] then 1 
when ([Sales]>=[20th Percentile]) and ([Sales]<[40th Percentile]) then 2 
when ([Sales]>=[40th Percentile]) and ([Sales]<[60th Percentile]) then 3 
when ([Sales]>=[60th Percentile]) and ([Sales]<[80th Percentile]) then 4 
when [Sales]>=[80th Percentile] then 5
else NULL
end

见附件截图 数据样本和计算


推荐阅读