Spotfire Custom Expression : Calculate (Num/Den) Percentages

拜拜、爱过 提交于 2019-12-08 13:17:24

问题


I am trying to plot Num/Den type percentages using OVER. But my thoughts does not appear to translate into spotfire custom expression syntax.

Sample Input:

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

Expected Out:

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%

My counts are working. I want to take the same Cumulative_N & Cumulative_D count and plot Percentage over [Axis.X] as a line chart.

Here's what I am using:

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

I understand SUM([Value]) is not the way to go. But I don't know what to use instead.

Also tried the one below as well, but did not:

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

Can you have a look ?


回答1:


I found a way to make it work, but it may not fit your overall solution. I should mention i used Count() versus UniqueCount() so that the results would mirror your desired output.

  1. Add a transformation to your current data table
    • Insert a calculated column Month([DOS]) as [TheMonth]
    • Set Row Identifers = [TheMonth]
    • Set value columns and aggregation methods to Count([CustomerID])
    • Set column titles to [Marker]
    • Leave the column name pattern as %M(%V) for %C

That will give you a new data table. Then, you can do your cumulative functions. I did them in a cross table to replicate your expected results. Insert a new cross table and set the values to:

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]

That should do it.




回答2:


I don't know if Spotfire released a fix or based on everyone's inputs I could get the syntax right. But here is the solution that worked for me.

For Columns D & N,

COUNT([CustomerID])

For columns Cumulative_D & Cumulative_N,

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

For column Percentage,

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



来源:https://stackoverflow.com/questions/37305536/spotfire-custom-expression-calculate-num-den-percentages

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!