简体   繁体   English

DAX(PowerPivot)中的加权标准偏差

[英]Weighted Standard Deviation in DAX (PowerPivot)

I've been attempting to program a PowerPivot Workbook that I've been using to calculate a weighted standard deviation. 我一直在尝试编写用于计算加权标准偏差的PowerPivot工作簿。

The problem is that when I use the code: 问题是当我使用代码时:

(the quality metric Q is weighted by the Product Tons for each record to get weighted statistics for variable periods [ie weeks, months, years]) (质量指标Q由每条记录的产品吨数加权,以获取可变期间[即周,月,年]的加权统计信息)

Product Q-St.d:=SQRT((SUMX('Table',((([PRODUCT_Q]-[W_Avg_Q]))^2)*[TOTAL_PRODUCT_TONS]))/(((COUNTX('Table',[Production_Q])-1)*[Product Tons])/COUNTX('Table',[Production_Q])))

It calculates the [W_Avg_Q] , which is the weighted average for Q, for each row as it iterates through instead of getting a weighted average for the whole context. 它在迭代时为每一行计算[W_Avg_Q] ,这是Q的加权平均值,而不是获得整个上下文的加权平均值。 I've learned pretty much all my DAX on the job or this site so I'm hoping there's some command to get the weighted average to calculate first. 我已经在工作或这个站点上学到了几乎所有的DAX,所以我希望有一些命令可以让您首先计算加权平均值。 Does anyone know such a command? 有人知道这样的命令吗? or another method of getting a weighted standard deviation out of DAX? 还是从DAX中获取加权标准偏差的另一种方法?

I think what you want to do is to declare [W_Avg_Q] a variable and then use it in your formula. 我认为您想要做的是声明[W_Avg_Q]变量,然后在公式中使用它。

Product Q-St.d :=
VAR WtdAvg = [W_Avg_Q]
RETURN SQRT((SUMX('Table',((([PRODUCT_Q]-WtdAvg))^2)*[TOTAL_PRODUCT_TONS])) /
    (((COUNTX('Table',[Production_Q])-1)*[Product Tons])/COUNTX('Table',[Production_Q])))

This way it gets calculated once in the proper context and then stored and reused within the formula. 这样,它就可以在适当的上下文中计算一次,然后在公式中存储和重用。

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

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