简体   繁体   English

Spotfire-在交叉表中将一行值除以另一行

[英]Spotfire - Dividing one row value with another in a cross table

I have a cross table which shows fruits sold across months as shown below: 我有一个交叉表,其中显示了跨月出售的水果,如下所示:
表格1]

Now, I would like to see a table (shown below) which divides one cell with another for a particular column: 现在,我希望看到一个表格(如下所示),该表格将一个特定的列的一​​个单元格与另一个单元格分开:
表2]

Please let me know if this is possible with an OVER statement. 请通过OVER语句告诉我是否可行。


UPDATE: 更新:

@Chris - I have transformed my original table in access and could create the below cross table visualization in Spotfire. @Chris-我已经转换了原始表格的访问权限,可以在Spotfire中创建以下交叉表格可视化。

Note: Apples sold, Oranges sold, watermelons sold are now separate columns after applying transformation. 注意:应用转换后,现在出售的苹果,出售的橙子,出售的西瓜是单独的列。

Cross table visualization 跨表可视化

However, I would like to see the cross table in the format below. 但是,我想以以下格式查看交叉表。

Transposed table 转置表

Please let me know if this is possible. 如果可以的话,请告诉我。 If this could be achieved with Iron Python script, I am fine with that. 如果可以使用Iron Python脚本实现此目的,那我很好。

Thank you! 谢谢!

As your data is in a tall skinny format, my original answer didn't work. 由于您的数据采用高皮包骨头的格式,因此我的原始答案无效。 I've kept the answer as part of this in case it helps someone else, see below. 我将答案保留在其中,以防它对其他人有所帮助,请参阅下文。

With your update, you seem to have managed to create a crosstable with the data you want. 通过更新,您似乎已经设法用所需的数据创建了一个交叉表。 While it would be helpful if you could show your exact axis expression on row-, column- and measure axis, I can try to illustrate how to transpose the data in the cross table as you want it to. 如果可以在行轴,列轴和度量轴上显示精确的轴表达式将很有帮助,但我可以尝试说明如何根据需要在交叉表中转置数据。 See the last last section for an explanation. 有关说明,请参见最后一节。

With a tall skinny format, you will not be able to use an OVER expression as you are looking to do explicit comparisons (at least I don't think it's possible). 如果采用高大的紧身格式,则在进行显式比较时将无法使用OVER表达式(至少我认为这是不可能的)。 First I'd like to note that you have to decide somehow which fruits you want to compare to each other, or you might want to compare all of them. 首先,我想指出,您必须以某种方式决定要比较哪些水果,或者可能要比较所有水果。 The exact solution would depend on what your real use case is and how dynamic you need it to be. 确切的解决方案取决于您的实际用例以及所需的动态性。

Possible solution: 可能的解决方案:

In your crosstable, define your row axis as (column names): 在交叉表中,将行轴定义为(列名):

<[Axis.Default.Names]>

Put your time axis on the column axis, for instance: 将时间轴放在列轴上,例如:

<BinByDateTime([Time],"Year.Month",1)>

On your measure axis, you will now add all the comparisons you are interested in, such as: 在测量轴上,现在将添加您感兴趣的所有比较,例如:

Sum(if([Fruit]="Apple", [Sold],null)) / Sum(if([Fruit]="Watermelon",[Sold],null)) as [Apples vs Watermelons],
Sum(if([Fruit]="Orange",[Sold],null)) / Sum(if([Fruit]="Watermelon",[Sold],null)) as [Oranges vs Watermelons]

Here's a link to how this looks with my own very small dummy dataset: 这是我自己的非常小的虚拟数据集的外观链接: 交叉表结果示例

It's possible you can combine this with user controls in a text area, and maybe the $map() expression function to make it more dynamic if needed. 您可以将其与文本区域中的用户控件结合使用,也可以将$ map()表达式函数结合使用,以在需要时使其更具动态性。 If you want a lot of dynamic behavior in this you might need to change to use a datafunction instead. 如果您需要很多动态行为,则可能需要更改以使用数据功能。


Old answer 旧答案

Below is my original answer, that includes presumption about the data that didn't apply in this case. 以下是我的原始答案,其中包括关于在这种情况下不适用的数据的假设。 Keeping it here if anyone else actually have this situation. 如果有人真的有这种情况,请将其保留在此处。

In table 1 you have two categorical axes, one for time and one for fruit. 在表1中,您有两个分类轴,一个代表时间,一个代表水果。 And the measure you are showing is the quantity of sold fruits. 而您显示的度量是已售水果的数量。

In table 2 I'd say that you only have one categorical axis, time. 在表2中,我会说您只有一个分类轴,即时间。 After that, you have two measured values, and your row axis would be '(Column Names)'. 之后,您将获得两个测量值,并且行轴将为“((列名称)”)。

The measures would be the count of apples divided by the count of oranges, as well as the count of oranges divided by the count of watermelons. 度量将是苹果数除以橙子数,以及橙子数除以西瓜数。 If you'd right click the measure axis and go to custom expression you would have something like: 如果右键单击度量轴并转到自定义表达式,您将得到类似以下内容的信息:

Sum([Apples]) / Sum([Oranges]) as [Apples vs. Oranges], 
Sum([Oranges]) / Sum([Watermelons]) as [Oranges vs. Watermelons]

Also, go to Properties -> Formatting and set your percentage formatting to your liking. 另外,转到“属性”->“格式化”,然后根据自己的喜好设置百分比格式。

Transpose in cross table 在交叉表中转置

It's a bit hard to understand from your screenshots, so I'll guess what your axis expressions are. 从屏幕截图中很难理解,所以我猜你的轴表达式是什么。 Even if I guess wrong, the same approach is applicable regardless initial state. 即使我猜错了,无论初始状态如何,都可以使用相同的方法。 You just need to swap the row axis with the column axis. 您只需要将行轴与列轴交换即可。 You can do it by using the axis selectors, or copy and paste from the custom expression editor. 您可以使用轴选择器来执行此操作,也可以通过自定义表达式编辑器进行复制和粘贴。 If this is the kind of configuration you have from the start: 如果从一开始就是这种配置,则: 原始交叉表配置

Then by swapping the axis expressions this is what you get: 然后通过交换轴表达式,您将获得: 转置交叉表配置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM