如何创建 DAX 度量/功率查询过程/其中 returns 来自具有相同日期和时间的另一行的值

how to create a DAX measure / power query process / which returns a value from another row, which has the same date & time

请在下面找到事实 table 的链接和所有 table 的概述。我想在 Fact table(“交易”)中创建一个 DAX 度量或新列,其中:

在我的 Fact table 屏幕截图中,我在 Excel 中手动添加了 EUR_amt 列以显示我想要创建的内容

我认为也可以添加该列,然后按时间和日期分组,这样以欧元为货币且 EUR_amt 为 0 的行将被删除。全部使用电源查询。那就更好了

(“货币”table 只是通过 PowerQuery 使用“交易”table 中“货币”列的不同值。我认为与这个问题无关)

非常感谢!

-YK

事实table“交易”

table
概览

计算列:

EUR_amt =
IF (
    OR ( transactions[type] <> "trade", transactions[currency] = "EUR" ),
    0,
    - LOOKUPVALUE (
        transactions[amount],
        transactions[Date], transactions[Date],
        transactions[Time], transactions[Time],
        transactions[currency], "EUR",
        0
    )
)

这是一种仅使用 Power Query 和高级编辑器来执行此操作的方法

  • 按数据和时间分组
  • 根据您的规则为每个子表生成自定义列
  • 展开子表,删除带有“0”的子表,并对列重新排序
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"type", type text}, {"currency", type text}, {"Date", type date}, {"Time", type time}, {"amount", type number}}),

//Group by Date and Time
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Date", "Time"}, {

//Add the Eur amt column to the grouped table
        {"EUR_amt", (t)=>let 

//determine relevant euro amt for each sub table
                eur= t[amount]{List.PositionOf(t[currency],"EUR")},

//add the column to each subtable basaed on conditions
                addCol = Table.AddColumn(t, "EUR_amt", 
                    each if [type]= "trade" and [currency]<>"EUR" then -eur else 0)
            in 
                addCol}}),

//Expand the new table
//Filter out the 0's
//reorder the columns
    #"Expanded EUR_amt" = Table.ExpandTableColumn(#"Grouped Rows", "EUR_amt", {"type", "currency", "amount", "EUR_amt"}, {"type", "currency", "amount", "EUR_amt"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded EUR_amt", each ([EUR_amt] <> 0)),
    #"Reordered Columns" = Table.ReorderColumns(#"Filtered Rows",{"type", "currency", "Date", "Time", "amount", "EUR_amt"})
in
    #"Reordered Columns"