![](/img/trans.png)
[英]Relate Table1 to table2 and show a field from table2 on table1
[英]Powerpivot retrieve cardinal value from data range of table2 to add as column to table1
使用 Excel 365 Powerquery。
我有兩個數據源table1
和table2
,其中包含以下條目:
table1:
ID | salary
===========
1 | 10
2 | 1000
table2:
ID | inclminval | exclmaxval | class | display
20 | 0 | 100 | P1 | Poor man
30 | 100 | 9999 | P9 | Wealthy
我想 append 到 table1:對於每個條目 table1.salary,
在 table2 上,添加列...自定義列...列名自定義和公式=1
一張表1,添加列...自定義列...列名自定義,公式=1
家..合並查詢...
使用 Full Outer join 選擇並匹配兩個表中的自定義列
使用新列頂部的箭頭 [x] 展開inclminval 、 exclmaxcal 、 class和顯示列
添加列...使用類似於公式的自定義列
= if [salary]>=[inclminval] and [salary]<[exclmaxcal] then "keep" else "remove"
使用新列頂部的箭頭過濾 [x] keep
刪除多余的列
表 1 的示例代碼
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Custom" = Table.AddColumn(Source, "Custom", each 1),
#"Merged Queries" = Table.NestedJoin(#"Added Custom",{"Custom"},Table2,{"Custom"},"Table2",JoinKind.FullOuter),
#"Expanded Table2" = Table.ExpandTableColumn(#"Merged Queries", "Table2", {"inclminval", "exclmaxcal", "class", "display"}, {"inclminval", "exclmaxcal", "class", "display"}),
#"Added Custom1" = Table.AddColumn(#"Expanded Table2", "Custom.1", each if [salary]>=[inclminval] and [salary]<[exclmaxcal] then "keep" else "remove"),
#"Filtered Rows" = Table.SelectRows(#"Added Custom1", each ([Custom.1] = "keep")),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Custom", "inclminval", "exclmaxcal", "display", "Custom.1"})
in #"Removed Columns"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.