如何用Power BI矩阵中的零替换空白值?

发布于 2025-01-21 10:35:50 字数 676 浏览 3 评论 0原文

我有一个以下格式的矩阵,在线和离线是措施。我想用零替换在线和离线的空白值。我该怎么做?

在线测量DAX(离线度量类似)

Online = 
VAR sale = 
    CALCULATE(
        SUM('Sales Data'[Sale Amount]), 
        FILTER(ALL('Sales Data'[Type of Sale]), 'Sales Data'[Type of Sale] = "Online")
    )

VAR purch = 
    CALCULATE(
        SUM('Sales Data'[Units Purchased]), 
        FILTER(ALL('Sales Data'[Type of Sale]), 'Sales Data'[Type of Sale] = "Online")
    )

RETURN IF(SELECTEDVALUE(Labels[Metric]) = "Sales Amount", sale, purch)

I have a matrix in the below format, where Online and Offline are measures. I want to replace blank values for Online and Offline with zero. How can I do this?

Sample Matrix

Online measure DAX (similar for Offline measure)

Online = 
VAR sale = 
    CALCULATE(
        SUM('Sales Data'[Sale Amount]), 
        FILTER(ALL('Sales Data'[Type of Sale]), 'Sales Data'[Type of Sale] = "Online")
    )

VAR purch = 
    CALCULATE(
        SUM('Sales Data'[Units Purchased]), 
        FILTER(ALL('Sales Data'[Type of Sale]), 'Sales Data'[Type of Sale] = "Online")
    )

RETURN IF(SELECTEDVALUE(Labels[Metric]) = "Sales Amount", sale, purch)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傻比既视感 2025-01-28 10:35:50

在您的措施中,您将需要将任何空白()结果专门设置为0。然后返回那些0而不是空白()。下面,我修改了您通过此调整提供的在线度量。

Online = 
VAR sale = 
    CALCULATE(
        SUM('Sales Data'[Sale Amount]), 
        FILTER(ALL('Sales Data'[Type of Sale]), 'Sales Data'[Type of Sale] = "Online")
    )
    
VAR saleWithZero = IF(ISBLANK(sale), 0, sale)

VAR purch = 
    CALCULATE(
        SUM('Sales Data'[Units Purchased]), 
        FILTER(ALL('Sales Data'[Type of Sale]), 'Sales Data'[Type of Sale] = "Online")
    )

VAR purchWithZero = IF(ISBLANK(purch), 0, purch)

RETURN IF(SELECTEDVALUE(Labels[Metric]) = "Sales Amount", saleWithZero, purchWithZero)

以下是我对此进行了测试的示例矩阵。

In your measures, you will want to specifically set any BLANK() results to 0. Then return those 0's instead of BLANK()'s. Below, I've modified the Online measure that you provided with this adjustment.

Online = 
VAR sale = 
    CALCULATE(
        SUM('Sales Data'[Sale Amount]), 
        FILTER(ALL('Sales Data'[Type of Sale]), 'Sales Data'[Type of Sale] = "Online")
    )
    
VAR saleWithZero = IF(ISBLANK(sale), 0, sale)

VAR purch = 
    CALCULATE(
        SUM('Sales Data'[Units Purchased]), 
        FILTER(ALL('Sales Data'[Type of Sale]), 'Sales Data'[Type of Sale] = "Online")
    )

VAR purchWithZero = IF(ISBLANK(purch), 0, purch)

RETURN IF(SELECTEDVALUE(Labels[Metric]) = "Sales Amount", saleWithZero, purchWithZero)

Below is a sample matrix that I tested this on.

Sample Matrix

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文