首页 文章

DAX Power BI - IF两个日期之间的声明

提问于
浏览
1

我试图在Power BI中的两个日期之间创建一个计算列IF语句 .

目前,我希望它看两个日期(在两个表中) . 如果匹配,则返回“True”,否则返回“False” .

On Time? = 
IF (
    TB1[C1]
        = TB2[C1],
    "Yes",
    "No"
)

我得到的错误是;

A single value for column 'C1' in table 'TB1' cannot be determined. 
This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or 
sum to get a single result.

数据样本是:

TABLE A              TABLE B
02 September 2010    02 September 2010
02 September 2010    03 September 2010
30 August 2010       29 August 2010

我应该使用什么语法来获得我想要的结果?

谢谢

1 回答

  • 1

    正如mthierba在评论中提到的,您可以使用RELATED()函数 . 值得注意的是,Power Pivot中的RELATED()仅在从多对一关系的多方面的表中调用时才起作用 . 即使您的数据在逻辑上是一对一的,Power Pivot也只能理解多对一关系,其中一个表将被视为多个 .

    IF(
        TB1[C1] = RELATED( TB2[C1] )
        ,"Yes"
        ,"No"
    )
    

    这只有在TB2是查找表时才有效 - 一方面 .

    如果TB2是多方面,则以下方法可行(尽管在TB2中):

    IF(
        TB2[C1] = RELATED( TB1[C1] )
        ,"Yes"
        ,"No"
    )
    

    如果任何给定的TB1 [C1]在TB2 [C1]中存在单个不同的值,则可以交替使用LOOKUPVALUE() .

    LOOKUPVALUE(
        TB2[C1]    // This is the field from which we will return a result
        ,TB2[<search field>]    // We will match this field against our lookup criterion - likely the relation field
        ,<search criterion>    // This would likely be relation field's value in TB1
    )
    

相关问题