如何根据另一个表的匹配条件重复表中的行

问题描述 投票:0回答:1

我在 A 和 B 下面有两张表。我想通过复制表 A 中的行,填充表 B 的日期列中缺少的日期,将表 A 转换为表 C,这将导致每个 id 的行数相等。

表A

id 日期 金额
1 2010年1月9日 4
1 2011年1月3日 3
2 2011/01/12 3
3 2011年1月3日 1
3 2011/01/06 1
3 2011年1月9日 1

表B

日期
2010年1月9日
2010年1月12日
2011年1月3日
2011/01/06
2011年1月9日

表C

id 日期 金额
1 2010年1月9日 4
1 2010年1月12日
1 2011年1月3日 3
1 2011/01/06
1 2011年1月9日
2 2010年1月9日
2 2010年1月12日
2 2011年1月3日 3
2 2011/01/06
2 2011年1月9日
3 2010年1月9日
3 2010年1月12日
3 2011年1月3日 1
3 2011/01/06 1
3 2011年1月9日 1
powerbi powerquery powerbi-desktop m
1个回答
0
投票

尝试

let  Source = Table.Distinct(Table.SelectColumns(TableA,{"id"})),
#"Added Custom" = Table.AddColumn(Source, "Dates", each Table.Distinct(TableA & TableB, {"Dates"})[Dates]),
#"Expanded Dates" = Table.ExpandListColumn(#"Added Custom", "Dates"),
#"Merged Queries" = Table.NestedJoin(#"Expanded Dates", {"id", "Dates"}, TableA, {"id", "Dates"}, "TableA", JoinKind.LeftOuter),
#"Expanded TableA" = Table.ExpandTableColumn(#"Merged Queries", "TableA", {"Amount"}, {"Amount"})
in #"Expanded TableA"
© www.soinside.com 2019 - 2024. All rights reserved.