简体   繁体   English

PowerPivot中的计算字段

[英]Calculated Field in PowerPivot

I have tried researching this question, but have had issues understanding DAX. 我曾尝试研究此问题,但在理解DAX时遇到了问题。

I am using PowerPivot instead of a normal pivot table so that I can use the distinct count feature. 我使用PowerPivot而不是普通的数据透视表,以便可以使用非重复计数功能。 I would like to create what in a classic pivot table would equate to a calculated field. 我想创建一个经典的数据透视表中等于计算字段的内容。 I put together an example in the picture below. 我在下图中整理了一个示例。

例

In the value section of the pivot table, I have a distinct count of the sales of red hats (column B). 在数据透视表的“价值”部分中,我对红色帽子(B列)的销售额有不同的统计。 To the right also in the value section, I have the count of total hat sales (all colors) (column C). 在“价值”部分的右侧,还有帽子销售总额(所有颜色)(C列)的计数。 I would like to add another column that displays the red hat sales as a percent of the total hat sales - The solution that I am looking for would divide the 'Distinct Count of Red Hat Sales' over the 'Count of Total Sales' using a field or measure in PowerPivot (Essentially what I have manually entered in column D). 我想添加另一列,以显示红帽销售量占其总帽子销售量的百分比-我要寻找的解决方案是使用以下方法将“红帽销售的不同数量”除以“总销售数量”字段或PowerPivot中的度量(基本上是我在D列中手动输入的内容)。

I believe that I am doing to have to use DAX to create a measure? 我相信我必须使用DAX来创建度量吗?

I am sure that this has probably been answered before, but I have had trouble finding exactly what I am asking. 我敢肯定,以前可能已经回答了这个问题,但是我很难找到我要问的问题。 Any help would be greatly appreciated. 任何帮助将不胜感激。

You need to create a DAX measure with the following formula: 您需要使用以下公式创建DAX度量:

= DIVIDE( [Count of Red Hats], [Count of Total Hats])

This function ignores division by zero errors. 该功能忽略零错误除法。 If such errors happen, the function by default displays blanks, but you can choose to display something else (DIVIDE function has third optional parameter). 如果发生此类错误,则默认情况下该函数显示空白,但您可以选择显示其他内容(DIVIDE函数具有第三个可选参数)。

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

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