我希望通過從另一個表中查找資料來在電源查詢中添加一個條件列。
例如,我的查找資料如下:

我的資料如下:

現在我想檢查我的資料中的數字是否在我的主資料的開始和結束之間以及是否滿足條件,然后我想通過將相應的“數字”單元格添加到我的資料中來添加一列。結果應如下所示:

有人可以指出我該怎么做嗎?
任何幫助是極大的贊賞。提前致謝
uj5u.com熱心網友回復:
使用查詢名稱LookupQuery和 file ...將您的頂級表格加載到 powerquery 中。關閉并加載。它應該有你顯示的列名
然后將中間源表加載到powerquery中并添加列...自定義列...與公式
= Table.SelectRows(LookupQuery,(x) => [Data] >= x[Begin] and [Data] <=x[End] )[Digits]{0}
完整代碼:
let Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Table.SelectRows(LookupQuery,(x) => [Data] >= x[Begin] and [Data] <=x[End] )[Digits]{0})
in #"Added Custom"
另一種方法是根據數字的長度進行匹配。這對于大型資料集會更好 將您的中間源資料加載到 powerquery 和
添加列...自定義列...帶有公式
= Text.Length(Text.From([Data]))
將您的資料與查找查詢合并,并將公式欄中的公式替換為:
= Table.NestedJoin(#"Added Custom", {"Custom"}, Table.AddColumn(LookupQuery, "Custom", each Text.Length(Text.From([Begin]))), {"Custom"}, "LookupQuery", JoinKind.LeftOuter)
展開數字列
第二種方法的完整代碼:
let Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Length(Text.From([Data]))),
#"Merged Queries" = Table.NestedJoin(#"Added Custom", {"Custom"}, Table.AddColumn(LookupQuery, "Custom", each Text.Length(Text.From([Begin]))), {"Custom"}, "LookupQuery", JoinKind.LeftOuter),
#"Expanded LookupQuery" = Table.ExpandTableColumn(#"Merged Queries", "LookupQuery", {"Digits"}, {"Digits"})
in #"Expanded LookupQuery"
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/451470.html
