使用Dax将空白值替换为零 [英] Replacing Blank values with Zero using Dax

查看:758
本文介绍了使用Dax将空白值替换为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用0代替空白值,为此我在表格模型中创建了一个度量,该度量的定义为:

I want to replace blank values with zero, for this i have created a measure in tabular model, the definition of that measure is :

Test:=if (
    calculate (
        sum ( quantity ),
        flag = 1, 
        title = "WEEKS"
    ) = blank (),
    0,
    calculate ( 
        sum ( quantity ),
        flag=1, 
        title = "WEEKS" 
    )
)

虽然效果很好,但是当我将此度量拖动到某些尺寸时,它会增加行数。 / p>

Although it works fine, but when i drag this measure with some dimensions it increases the number of rows.

+-------------+-------------+------+
| Dimension A | Dimension B | Test |
+-------------+-------------+------+
| A           | C           |    0 |
| B           | X           |    0 |
| A           | X1          |    0 |
| B           | X1          |    0 |
| A           | G           |    0 |
| A           | D           |    0 |
+-------------+-------------+------+

它会增加行,例如,有一个笛卡尔坐标,当我删除if条件时,它就可以正常工作。

It increase the rows like, there is a Cartesian, and when i remove the if condition it just works fine.

+-------------+-------------+------+
| Dimension A | Dimension B | Test |
+-------------+-------------+------+
| A           | C           |    0 |
| B           | X           |  270 |
| A           | X1          |  101 |
| B           | X1          |   44 |
| A           | G           |   12 |
| A           | D           |   10 |
+-------------+-------------+------+

那么可能是什么原因,我只想将空白值替换为零。

So what could be the reason, I simply want to replace blank values with zero.

推荐答案

如果您想将blank()值更改为零,只需在计算的末尾添加0:

If you want to change blank() values with zero, just add a 0 at the end of you calculate:

Test:=
calculate (
    sum ( quantity ),
    flag = 1, 
    title = "WEEKS"
) + 0

这篇关于使用Dax将空白值替换为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆