Spotfire自定义表达式:计算(Num / Den)百分比

时间:2016-05-18 16:40:30

标签: tibco spotfire

我正在尝试使用OVER绘制Num / Den类型百分比。但我的想法似乎并没有转化为spotfire自定义表达式语法。

示例输入:

RecordID  CustomerID  DOS       Age  Gender  Marker
9621854   854693      09/22/15  37   M       D
9732721   676557      09/18/15  65   M       D
9732700   676557      11/18/15  65   M       N
9777003   5514882     11/25/15  53   M       D
9853242   1753256     09/30/15  62   F       D
9826842   1260021     09/30/15  61   M       D
9897642   3375185     09/10/15  74   M       N
9949185   9076035     10/02/15  52   M       D
10088610  3512390     09/16/15  33   M       D
10120650  41598       10/11/15  67   F       N
9949185   9076035     10/02/15  52   M       D
10088610  3512390     09/16/15  33   M       D
10120650  41598       09/11/15  67   F       N

期待:

Row Labels  D  Cumulative_D  N  Cumulative_N  Percentage
Sep         6  6             2  2             33.33%
Oct         2  8             1  3             37.50%
Nov         1  9             1  4             44.44%

我的计数正在发挥作用。 我想采取相同的Cumulative_N&累计_计数并将[Axis.X]上的百分比绘制为折线图。

以下是我正在使用的内容:

UniqueCount(If([Marker]="N",[CustomerID])) / UniqueCount(If([Marker]="D",[CustomerID])) THEN SUM([Value]) OVER (AllPrevious([Axis.X])) as [CumulativePercent]

我理解SUM([Value])不是要走的路。但我不知道该用什么。

也试过下面的那个,但没有:

UniqueCount(If([Marker]="N",[CustomerID])) OVER (AllPrevious([Axis.X])) / UniqueCount(If([Marker]="D",[CustomerID])) OVER (AllPrevious([Axis.X])) as [CumulativePercent]

你能来看看吗?

2 个答案:

答案 0 :(得分:0)

我找到了一种方法,但它可能不适合您的整体解决方案。我应该提到我使用Count()UniqueCount(),以便结果反映出您想要的输出。

  1. 向您当前的数据表添加转换
    • 插入计算列Month([DOS]) as [TheMonth]
    • 设置行标识= [TheMonth]
    • 将值列和聚合方法设置为Count([CustomerID])
    • 将列标题设置为[Marker]
    • 将列名称模式保留为%M(%V) for %C
  2. 这将为您提供一个新的数据表。然后,您可以执行累积功能。我在交叉表中完成了它们以复制您的预期结果。插入新的交叉表并将值设置为:

    Sum([D]), Sum([N]), Sum([D]) OVER (AllPrevious([Axis.Rows])) as [Cumulative_D], 
    Sum([N]) OVER (AllPrevious([Axis.Rows])) as [Cumulative_N], 
    Sum([N]) OVER (AllPrevious([Axis.Rows])) / Sum([D]) OVER (AllPrevious([Axis.Rows])) as [Percentage]
    

    应该这样做。

答案 1 :(得分:0)

我不知道Spotfire是否发布了修复程序或基于每个人的输入我可以正确地使用语法。但是这个解决方案对我有用。

对于列D& N,

COUNT([CustomerID])

enter image description here

对于Cumulative_D&列。 Cumulative_N,

Count([CustomerID]) OVER (AllPrevious([Axis.X])) where [Axis.X] is DOS(Month), Marker

enter image description here

对于列百分比,

Count(If([Marker]="N",[CustomerID])) OVER (AllPrevious([Axis.X])) / Count(If([Marker]="D",[CustomerID])) OVER (AllPrevious([Axis.X]))
where [Axis.X] is DOS(Month)

enter image description here