使用过滤器从另一个 table 获取最短日期

Get min date from another table with filter

我有两个 table。 id 和用户 id 列之间存在关系。我想在用户 table 中为发票类型 'A'.

添加一个包含用户第一笔交易的计算列

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

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

用户table:

ID 姓名
1 约翰·史密斯
2 艾伦·沃克

交易table:

用户编号 交易日期 发票类型
1 2021-02-01 一个
1 2021-02-25 一个
1 2021-02-25 B
2 2021-03-05 一个
2 2021-01-23 B

这是计算列的正确 DAX 代码,只需删除 FILTER 语句,因为这会更改 CALCULATE 中的筛选上下文以查看 Invoice type = "A" 所在的所有行, 无论 User ID.

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

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

行的当前过滤上下文中提供
Min Date = 
CALCULATE ( 
    MIN ( 'Transaction'[transaction date] ) , 
    FILTER ( 
        CALCULATETABLE ( 'Transaction' ) , 
        'Transaction'[Invoice type] = "A"
    )
)