有没有一种特定的方法可以有条件地在PowerBI的列中添加内容? [英] Is there a specific way to conditionally add within a column in PowerBI?

查看:58
本文介绍了有没有一种特定的方法可以有条件地在PowerBI的列中添加内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PowerBI的列中是否有条件地添加特定方法?

Is there a specific way to conditionally add within a column in PowerBI?

样本数据:

Lang|Book_Type|Number|Book_Type (groups)
------------------------
A   |  B1     |  2   | B1
------------------------
B   |  B1     |  2   | B1
------------------------
C   |  B1     |  3   | B1
------------------------
A   |  B2     |  4   | B2
------------------------
B   |  B2     |  2   | B2
------------------------
A   |  B3     |  2   | B3
------------------------
A   |  B4     |  2   | B4
------------------------
B   |  B4     |  5   | B4
------------------------

所以,我想做的是,我想要第5列,其中与每一行相对应,我拥有该类型的图书总数,即在第5列中与第1,2和3行并列,我想要:7(= 2 + 2 + 3),并在第5列的第4行和第5行旁边,我想要:6(= 4 + 2).我也尝试过分组,但还是一样.有没有办法在DAX中做到这一点?我尝试了以下代码,但给出了循环依赖错误.

So, what I want to do is that I want a 5th column, wherein corresponding to each row, I have the total number of books in that type, i.e., alongside row 1,2 and 3, in the 5th column, I would want: 7(=2+2+3), and alongside row 4 and 5, in the 5th column, I would want: 6(=4+2). I also tried grouping, but it's still the same. Is there a way to do this in DAX? I tried the following code, but it gives a circular dependency error.

SUMX (
    'Book_store',
    IF (
         ( Book_store[Book_Type] = Book_store[Book_Type (groups)] ),
        CALCULATE ( SUM ( 'Book_store'[Number] ) ),
        BLANK ()
    )
)

推荐答案

之所以是循环依赖项,是因为您在SUMX的第一个参数(包括您要添加的列...,但您无法引用尚未创建的列.)

The reason this is a circular dependency is that you are calling the entire table as part of the definition of the new column in the first argument of SUMX (which includes the column you're adding... but you can't reference something you haven't yet created).

更好的方法可能是这样

CALCULATE (
    SUM ( Book_store[Number] ),
    ALLEXCEPT ( Book_store, Book_store[Book_type (groups)] )
)

这告诉它对Number列求和,而忽略除 所指定的所有列之外的所有列.

This tells it to sum the Number column ignoring all columns except the one specified.

这篇关于有没有一种特定的方法可以有条件地在PowerBI的列中添加内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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