【问题标题】:Get min date from another table with filter使用过滤器从另一个表中获取最小日期
【发布时间】:2021-08-09 06:50:25
【问题描述】:

我有两张桌子。 id 和用户 id 列之间存在关系。我想在用户表中添加一个计算列,其中包含用户的第一笔交易,发票类型为“A”。

当我使用: Calculate(min(Transaction[transaction date])) 它工作正常,但我需要过滤发票类型。当我使用Calculate(min(Transaction[transaction date]),Filter(Transaction,Invoice type="A")) 时,我只得到 2021-02-01 并且不动产。

实现这一目标最有效的方法是什么?

用户表:

ID Name
1 John Smith
2 Alan Walker

交易表:

user id transaction date Invoice type
1 2021-02-01 A
1 2021-02-25 A
1 2021-02-25 B
2 2021-03-05 A
2 2021-01-23 B

【问题讨论】:

    标签: powerbi dax


    【解决方案1】:

    这是计算列的正确 DAX 代码,只需删除 FILTER 语句,因为这会更改 CALCULATE 中的过滤器上下文以查看 Invoice type = "A" 所在的所有行,而不管 User ID

    Minimum Date = 
    CALCULATE (
        MIN ( 'Transaction'[transaction date] ),
        'Transaction'[Invoice type] = "A"
    )
    

    由于您需要上下文转换来为您提供从Users 表到Transactions 表的行上下文,您可以选择使用这种过滤语句,您要过滤的表也在当前表中提供在Users 中过滤您的行的上下文:

    Min Date = 
    CALCULATE ( 
        MIN ( 'Transaction'[transaction date] ) , 
        FILTER ( 
            CALCULATETABLE ( 'Transaction' ) , 
            'Transaction'[Invoice type] = "A"
        )
    )
    

    【讨论】:

      猜你喜欢
      • 2021-03-16
      • 2021-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-12
      • 1970-01-01
      • 2021-09-22
      • 1970-01-01
      相关资源
      最近更新 更多