首页 > 解决方案 > 仅当另一列具有值 DAX 时 PowerBi 才计算日期

问题描述

试图利用 powerbi 帮助我计算日期。目前,如果“spend_start_Result”列有值,它正在正确计算,但如果该列没有值,它仍在计算并给我一个 1899 年 12 月 30 日的日期。我的 DAX 代码有问题吗?

Arch_review_Calc =
IF (
    Projects[spend_start_Result] = BLANK (),
    0,
    IF (
        Projects[Complexity] = "Low",
        Projects[spend_start_Result] - 45,
        IF (
            Projects[Complexity] = "Medium",
            Projects[spend_start_Result] - 60,
            IF ( Projects[Complexity] = "High", Projects[spend_start_Result] - 90, 0 )
        )
    )
)

如果该行中的spend_start_result 列为空白,我希望该行中的Arch_review_calc 列为空白。相反,它仍在计算,我不确定我哪里出错了。

标签: powerbidax

解决方案


您的代码用零替换空格,这些零被格式化为日期。为避免这种情况,请使用 BLANK() 函数代替零。

我会重写你的公式如下:

   Arch_review_Calc =
    IF (
        ISBLANK ( Projects[spend_start_Result] ), BLANK (),
        SWITCH (
            TRUE,
            Projects[Complexity] = "Low", Projects[spend_start_Result] - 45,
            Projects[Complexity] = "Medium", Projects[spend_start_Result] - 60,
            Projects[Complexity] = "High", Projects[spend_start_Result] - 90,
            BLANK ()
        )
    )

我不确定最后一个空白(在 SWITCH 语句内) - 如果您想要 0 而不是空白,请将 BLANK() 替换为 0。


推荐阅读