【问题标题】:DAX suggestions to generate specific weighted average measure in PowerBI?DAX 建议在 PowerBI 中生成特定加权平均度量?
【发布时间】:2018-10-12 15:36:47
【问题描述】:

我正在尝试在 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。

请注意,其中一个复杂因素是存在 *blank* 单元格的事实。

任何人都可以建议在 PowerBI 中使用计算度量(或其他方式)执行此操作的方法吗?

【问题讨论】:

    标签: powerbi dax weighted-average


    【解决方案1】:

    您可以将SurveyData 表中每一行的权重相加,然后除以行数

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

    或者简单地使用平均函数

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

    【讨论】:

    • 嗨,亚历克西斯!感谢您的回复,非常有帮助。然而,我意识到我的例子对于我遇到的问题来说太简单了。对此我很抱歉。我现在对其进行了更改以更好地反映我的数据集。我现在的问题是您的度量标准运行良好,但我如何使其适用于也具有相关信息的另一列?我添加了'surveydata'[Do you agree with X?]'weights'[Likert] 列以更好地反映我的问题。再次感谢您,亚历克西斯!非常有用。
    • 您需要在另一列上建立关系。查看USERELATIONSHIPLOOKUPVALUE 函数。例如,请参见此处:sqlbi.com/articles/userelationship-in-calculated-columns
    猜你喜欢
    • 2020-01-15
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 2021-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多