DAX建议在PowerBI中生成特定的加权平均度量?

时间:2018-10-12 15:36:48

标签: powerbi dax weighted-average

我正在尝试在PowerBi中为调查数据制定加权平均量度。我目前有以下两个表(简化):

调查数据

ID           How would you score the service?      Do you agree with X?
---------------------------------------------------------------------------
23           Fair                                  Agree
24           Poor                                  Strongly disagree
25           Fair                                  Agree
26           Very poor                             *blank*
27           Very good                             Strongly agree

重量

Weight         Score         Likert
-------------------------------------------------
 1             Very poor     Strongly disagree
 2             Poor          Disagree
 3             Fair          Neither agree nor disagree
 4             Good          Agree
 5             Very good     Strongly Agree

'surveydata'[How would you score the service?]'weights'[weight]之间目前存在一种关系。

我要计算的加权平均公式如下:

                (x1 * w1) + (x2 * w2) + ... (xn * wn)
Weighted Ave = ___________________________________________
                          x1 + x2 + ... xn

位置:

w = weight of answer choice
x = response count for answer choice

对于上面的示例,我需要两种度量-'surveydata'[How would you score the service?]的加权平均值和'surveydata'[Do you agree with X?]的加权平均值。

对于上面的示例,'surveydata'[How would you score the service?]的加权平均度量应为2.8。

请注意,并发症之一是存在 *空白* 个单元格的事实。

任何人都可以建议在PowerBI中使用计算得出的度量(或其他方法)做到这一点的方法吗?

1 个答案:

答案 0 :(得分:0)

您可以对SurveyData表中每一行的权重求和,然后除以行数

Weighted Ave =
DIVIDE(
    SUMX(SurveyData, RELATED(Weights[Weight])),
    COUNTROWS(SurveyData)
)

或者只是使用平均值函数

Weighted Ave = AVERAGEX(SurveyData, RELATED(Weights[Weight]))