簡體   English   中英

Powerpivot 從 table2 的數據范圍中檢索基數值以作為列添加到 table1

[英]Powerpivot retrieve cardinal value from data range of table2 to add as column to table1

使用 Excel 365 Powerquery。

我有兩個數據源table1table2 ,其中包含以下條目:

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 的范圍 table2.inclminval <= table1.salary < table2.exclmaxval 和
  • 使用 table2.class 的匹配對應條目作為 table1 中的新計算列。

在 table2 上,添加列...自定義列...列名自定義和公式=1

一張表1,添加列...自定義列...列名自定義,公式=1

家..合並查詢...

使用 Full Outer join 選擇並匹配兩個表中的自定義

在此處輸入圖像描述

使用新列頂部的箭頭 [x] 展開inclminvalexclmaxcalclass顯示

在此處輸入圖像描述

添加列...使用類似於公式的自定義列

= 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM