首页 文章

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

提问于
浏览
0

我试图使用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和Cumulative_D计数,并将[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

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

    • 向当前数据表添加转换

    • 插入计算列 Month([DOS]) as [TheMonth]

    • Set Row Identifers = [TheMonth]

    • 将值列和聚合方法设置为 Count([CustomerID])

    • 将列 Headers 设置为 [Marker]

    • 将列名模式保留为 %M(%V) for %C

    这将为您提供一个新的数据表 . 然后,您可以执行累积功能 . 我在交叉表中完成了它们以复制您的预期结果 . 插入新的交叉表并将值设置为:

    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]
    

    应该这样做 .

  • 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

相关问题