如何在 Power BI 中合并两个基于非键表的表
Posted
技术标签:
【中文标题】如何在 Power BI 中合并两个基于非键表的表【英文标题】:How to merge two tables based off key table in Power BI 【发布时间】:2021-07-01 14:54:58 【问题描述】:我有 3 个 csv 输入到 Power BI,其中两个包含来自 2 个不同服务的时间跟踪信息,一个包含从它们的名称到各自 ID 的映射,如以下列标题所示:
-
Timestamp, 7P_ID, time_tracked, Work item type, ...
Timestamp, ZD_ID, time_tracked, ticket id, ... (它们有一些不同的列标题)
employee_name, 7P_ID, ZD_ID
我想制作一个表格(或至少以某种方式组合这些数据)来组合这些表格,所以我有以下标题:
Timestamp, employee_name, time_tracked, Work item type, ticket id, ...
有什么想法吗?
编辑:例如...
Timestamp | 7P_ID | time_tracked | work item type |
---|---|---|---|
2021-09-02 | 333-3 | 90 | task |
... | ... | ... | ... |
Timestamp | ZD_ID | time_tracked | ticket id |
---|---|---|---|
2021-09-03 | 444-444 | 67 | 24601 |
... | ... | ... | ... |
Employee Name | 7P_ID | ZD_ID |
---|---|---|
Jeff Bozos | 333-3 | 444-444 |
... | ... | ... |
我想要……
Timestamp | Employee name | time_tracked | work item type | ticket id |
---|---|---|---|---|
2021-09-02 | Jeff Bozos | 90 | task | |
2021-09-03 | Jeff Bozos | 67 | 24601 | |
... | ... | ... | ... | ... |
当然会有多个员工,每个员工都会出现多次
编辑 2:或者,使用密钥文件将“名称”列附加到我的两次记录文件中也一样好,但这也是我不知道该怎么做的事情。
【问题讨论】:
添加一些示例数据会有所帮助 我已经更新了帖子^ 【参考方案1】: let
T1 =
let
Source = Web.BrowserContents(
"https://***.com/questions/68212487/how-to-merge-two-tables-based-off-key-table-in-power-bi"
),
#"Extracted Table From html" = Html.Table(
Source,
"Column1", "DIV.s-table-container:nth-child(7) > TABLE.s-table > * > TR > :nth-child(1)",
"Column2", "DIV.s-table-container:nth-child(7) > TABLE.s-table > * > TR > :nth-child(2)",
"Column3", "DIV.s-table-container:nth-child(7) > TABLE.s-table > * > TR > :nth-child(3)",
"Column4", "DIV.s-table-container:nth-child(7) > TABLE.s-table > * > TR > :nth-child(4)"
,
[RowSelector = "DIV.s-table-container:nth-child(7) > TABLE.s-table > * > TR"]
),
#"Changed Type" = Table.TransformColumnTypes(
#"Extracted Table From Html",
"Column1", type text,
"Column2", type text,
"Column3", type text,
"Column4", type text
),
#"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars = true]),
#"Changed Type1" = Table.TransformColumnTypes(
#"Promoted Headers",
"Timestamp", type text,
"7P_ID", type text,
"time_tracked", type text,
"work item type", type text
),
#"Removed Bottom Rows" = Table.RemoveLastN(#"Changed Type1", 1),
#"Renamed Columns" = Table.RenameColumns(#"Removed Bottom Rows", "7P_ID", "ID")
in
#"Renamed Columns",
T2 =
let
Source = Web.BrowserContents(
"https://***.com/questions/68212487/how-to-merge-two-tables-based-off-key-table-in-power-bi"
),
#"Extracted Table From Html" = Html.Table(
Source,
"Column1", "DIV.s-table-container:nth-child(8) > TABLE.s-table > * > TR > :nth-child(1)",
"Column2", "DIV.s-table-container:nth-child(8) > TABLE.s-table > * > TR > :nth-child(2)",
"Column3", "DIV.s-table-container:nth-child(8) > TABLE.s-table > * > TR > :nth-child(3)",
"Column4", "DIV.s-table-container:nth-child(8) > TABLE.s-table > * > TR > :nth-child(4)"
,
[RowSelector = "DIV.s-table-container:nth-child(8) > TABLE.s-table > * > TR"]
),
#"Changed Type" = Table.TransformColumnTypes(
#"Extracted Table From Html",
"Column1", type text,
"Column2", type text,
"Column3", type text,
"Column4", type text
),
#"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars = true]),
#"Changed Type1" = Table.TransformColumnTypes(
#"Promoted Headers",
"Timestamp", type text,
"ZD_ID", type text,
"time_tracked", type text,
"ticket id", type text
),
#"Removed Bottom Rows" = Table.RemoveLastN(#"Changed Type1", 1),
#"Renamed Columns" = Table.RenameColumns(#"Removed Bottom Rows", "ZD_ID", "ID")
in
#"Renamed Columns",
T3 =
let
Source = Web.BrowserContents(
"https://***.com/questions/68212487/how-to-merge-two-tables-based-off-key-table-in-power-bi"
),
#"Extracted Table From Html" = Html.Table(
Source,
"Column1", "DIV.s-table-container:nth-child(9) > TABLE.s-table > * > TR > :nth-child(1)",
"Column2", "DIV.s-table-container:nth-child(9) > TABLE.s-table > * > TR > :nth-child(2)",
"Column3", "DIV.s-table-container:nth-child(9) > TABLE.s-table > * > TR > :nth-child(3)"
,
[RowSelector = "DIV.s-table-container:nth-child(9) > TABLE.s-table > * > TR"]
),
#"Changed Type" = Table.TransformColumnTypes(
#"Extracted Table From Html",
"Column1", type text, "Column2", type text, "Column3", type text
),
#"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars = true]),
#"Changed Type1" = Table.TransformColumnTypes(
#"Promoted Headers",
"Employee Name", type text, "7P_ID", type text, "ZD_ID", type text
),
#"Removed Bottom Rows" = Table.RemoveLastN(#"Changed Type1", 1),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(
#"Removed Bottom Rows",
"Employee Name",
"Attribute",
"Value"
)
in
#"Unpivoted Columns",
#"T1+T2" = T1 & T2,
#"Merged Queries" = Table.NestedJoin(#"T1+T2", "ID", T3, "Value", "T1+T2", JoinKind.LeftOuter),
#"Expanded T1+T2" = Table.ExpandTableColumn(
#"Merged Queries",
"T1+T2",
"Employee Name",
"Employee Name"
)
in
#"Expanded T1+T2"
【讨论】:
以上是关于如何在 Power BI 中合并两个基于非键表的表的主要内容,如果未能解决你的问题,请参考以下文章
如何从两列数据制作一个 Power BI 饼图小部件/或将两个饼图合并为一个