每個人:
我有一張包含這些日期的表格:

我有另一個包含日期和所有者串列的表格:

我需要合并/加入這兩個表,以便交易日期與最接近的上一個開始日期相匹配,使其看起來像這樣:

我嘗試將 XLOOKUP 與“-1”一起使用,但這是一個問題,因為 XLOOKUP 檢索到交易日期 4/16/2017 的第一條記錄(有 2 個匹配項),并且我無法在 Power Query 上合并,因為沒有確切的日期匹配項. 還有其他方法嗎?
謝謝你。
uj5u.com熱心網友回復:
假設此表名為 Table4,由于 e 和 f 的日期重復,您首先需要進行分組。

let
Source = Excel.CurrentWorkbook(){[Name="Table4"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Start Date", type text}, {"Owner", type text}}),
#"Changed Type with Locale" = Table.TransformColumnTypes(#"Changed Type", {{"Start Date", type date}}, "en-US"),
#"Grouped Rows" = Table.Group(#"Changed Type with Locale", {"Start Date"}, {{"All", each _, type table [Start Date=nullable date, Owner=nullable text]}})
in
#"Grouped Rows"
假設此表名為 Table3,您可以按照
該表的代碼是
let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Transaction Dates", type text}}),
#"Changed Type with Locale" = Table.TransformColumnTypes(#"Changed Type", {{"Transaction Dates", type date}}, "en-US"),
#"Added Custom" = Table.AddColumn(#"Changed Type with Locale", "Custom", (i) => Table.Last( Table.Sort( Table.SelectRows(Table4,each [Start Date] <= i[Transaction Dates]),{"Start Date", Order.Ascending}))),
#"Expanded Custom" = Table.ExpandRecordColumn(#"Added Custom", "Custom", {"Start Date", "All"}, {"Custom.Start Date", "Custom.All"}),
#"Expanded Custom.All" = Table.ExpandTableColumn(#"Expanded Custom", "Custom.All", {"Owner"}, {"Owner"})
in
#"Expanded Custom.All"

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/476781.html
上一篇:如果它們有相互段,則加入行串列?
