【问题标题】:Power BI: Calculate difference columnPower BI:计算差异列
【发布时间】:2021-08-19 08:08:09
【问题描述】:

我在计算矩阵中的差异时遇到了一个问题。例如, 在下图中,您可以看到空白处,差异为 0,而应该为 3。我使用以下公式计算差异:

Diff =
CALCULATE (
    DISTINCTCOUNT ( 'Question and Answer'[Respondent ID] ),
    FILTER (
        'Question and Answer',
        'Question and Answer'[Start Date] = MAX ( 'Question and Answer'[Start Date] )
    )
)
    - CALCULATE (
        DISTINCTCOUNT ( 'Question and Answer'[Respondent ID] ),
        FILTER (
            'Question and Answer',
            'Question and Answer'[Start Date] = MIN ( 'Question and Answer'[Start Date] )
        )
    )

任何帮助将不胜感激。谢谢!

【问题讨论】:

    标签: powerbi difference


    【解决方案1】:

    我可能弄错了,但您似乎在计算数据的开始日期和结束日期之间的差异,并按性别过滤。 '而不说'只有一天的数据点,因此它会遵循差异为零。

    会发生什么:3-3 = 0。

    解决此问题的方法是构建逻辑来评估最小和最大开始日期是否相等,并传入 0 而不是值。

    Diff = 
    CALCULATE (
        DISTINCTCOUNT ( 'Question and Answer'[Respondent ID] ),
        FILTER (
            'Question and Answer',
            'Question and Answer'[Start Date] = MAX ( 'Question and Answer'[Start Date] )
        )
    )
        - **IF(DATEDIFF(MAX('Question and Answer'[Start Date]),MIN('Question and Answer'[Start Date]),DAY) = 0, 0** ,
        
            CALCULATE (
                DISTINCTCOUNT ( 'Question and Answer'[Respondent ID] ),
                FILTER (
                    'Question and Answer',
                    'Question and Answer'[Start Date] = MIN ( 'Question and Answer'[Start Date] )
                )
            )
        )
    

    两个星号之间的代码行使代码按预期工作。

    【讨论】:

      猜你喜欢
      • 2022-11-30
      • 2020-04-30
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-10
      相关资源
      最近更新 更多