Spotfire调试经验-使用DenseRank函数进行TopN分析

本文介绍如何使用Spotfire中的DenseRank函数实现两地天气TopN对比分析,通过正确设置函数参数来展示每座城市最常见的六种天气及其出现概率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

之前已经写过一篇文章介绍了DesneRank函数的用法。

所以,我以为我会用这个函数了,却发现还没有完全掌握。


需求描述:对两地(Trellis by 城市)天气进行进行TopN对比分析。说人话就是,在两张饼图上分别显示两座城市的最常见的6种天气,并按出现概率排序,其他所有天气归类为“其他”。


按照我的理解,我一开始用了这样一个公式(注意:这个公式不能达到预期效果):

If(DenseRank(Count() OVER ([城市],[天气]),"desc")<=6,[天气],"其他"),以及,

If(DenseRank(Count() OVER ([天气]),"desc",[城市])<=6,[天气],"其他"),

经过多次的失败和不断尝试,终于功夫不负有心人,写出了正确的表达式:

If(DenseRank(Count() OVER ([城市],[天气]),"desc",[城市])<=6,[天气],"其他")

这个公式的核心在于,因为要同Trellis by配合使用,天气的排名要在不同城市内进行,所以denserank函数中除了使用第一个参数:Count() OVER ([城市],[天气])外,还要加入第二个参数:[城市]。


这时,我才有所明白Spotfire参考文档对DenseRank函数的描述了:

DenseRank(Arg1, Arg2, Arg3...):

Returns an integer value ranking of the values in the selected column. The first argument is the column to be ranked.

An optional argument is a string determining whether to use an ascending (default) or a descending ranking. For the highest value to retrieve rank 1, use the argument "desc", for the lowest value to retrieve rank 1, use "asc".

Ties are given the same rank value and the highest ranking number equals the number of unique values in the column.

Additional column arguments (optional) can be used when the column should be split into separately ranked categories.

Examples:

DenseRank([Sales])

DenseRank([Sales], "desc", [Region])


再次感受到了Spotfire的强大!


附上Spotfire对比图表:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值