我在 PowerBI 中有一个相当大的表,如下所示:
日期1 | ID1 | ID2 | 日期2 | 金额1 | 金额2 | 金额3 |
---|---|---|---|---|---|---|
2022年2月4日 | 1234 | 12 | 2022年2月4日 | 5 | 3 | 8 |
2022年2月4日 | 1234 | 13 | 2022年2月4日 | 5 | 3 | 8 |
2022年2月4日 | 1235 | 14 | 2022年2月4日 | 6 | 3 | 9 |
2022年2月6日 | 1234 | 10 | 2022年2月6日 | 20 | 23 | 46 |
2022年2月6日 | 1238 | 11 | 2022年2月6日 | 20 | 23 | 46 |
2022年2月6日 | 1238 | 14 | 2022年2月6日 | 26 | 23 | 49 |
如上述情况,如果05.02.2022 缺失,我希望我的最终结果看起来像
日期1 | ID1 | ID2 | 日期2 | 金额1 | 金额2 | 金额3 |
---|---|---|---|---|---|---|
2022年2月4日 | 1234 | 12 | 2022年2月4日 | 5 | 3 | 8 |
2022年2月4日 | 1234 | 13 | 2022年2月4日 | 5 | 3 | 8 |
2022年2月4日 | 1235 | 14 | 2022年2月4日 | 6 | 3 | 9 |
2022年2月5日 | 1234 | 12 | 2022年2月5日 | 5 | 3 | 8 |
2022年2月5日 | 1234 | 13 | 2022年2月5日 | 5 | 3 | 8 |
2022年2月5日 | 1235 | 14 | 2022年2月5日 | 6 | 3 | 9 |
2022年2月6日 | 1234 | 10 | 2022年2月6日 | 20 | 23 | 46 |
2022年2月6日 | 1238 | 11 | 2022年2月6日 | 20 | 23 | 46 |
2022年2月6日 | 1238 | 14 | 2022年2月6日 | 26 | 23 | 49 |
这意味着 2022 年 2 月 4 日以来的所有内容都是复制粘贴的,只是添加了一个新日期 2022 年 2 月 5 日。
也有这样的情况:2 或 3 天内没有可用数据,因此在这些情况下,我需要最后一个已知日期的所有数据,直到我们再次获得数据。
有人知道如何在PowerBI中实现这个吗?
谢谢!
以下内容应该适合您。我已将您的示例数据查询命名为 Table。
创建一个新查询并粘贴以下代码。这个新查询引用名为 Table 的示例数据查询,因此您将有两个查询。
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDRMzDSMzIwMlKK1QFyTVG5ZghuLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Date"}, Table, {"Date1"}, "Table", JoinKind.LeftOuter),
#"Added Custom" = Table.AddColumn(#"Merged Queries", "Count", each if Table.RowCount([Table]) > 0 then [Table] else null),
#"Filled Down" = Table.FillDown(#"Added Custom",{"Count"}),
#"Added Custom1" = Table.AddColumn(#"Filled Down", "Custom", each if Table.RowCount([Table]) > 0 then [Table] else Table.ReplaceValue([Count],[Count]{0}[Date1],[Date],Replacer.ReplaceValue,{"Date1", "Date2"})),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Table", "Count"}),
#"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Date1", "ID1", "ID2", "Date2", "Amount1", "Amount2", "Amount3"}, {"Date1", "ID1", "ID2", "Date2", "Amount1", "Amount2", "Amount3"}),
#"Removed Columns1" = Table.RemoveColumns(#"Expanded Custom",{"Date"})
in
#"Removed Columns1"
如果您需要填写更多日期,只需更改步骤 1 中的日期范围即可,您应该能够根据您的数据自动生成该范围。我的看起来像这样。
我更新了查询如下:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDRMzDSMzIwMlKK1QFyTVG5ZghuLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Date"}, Table, {"Date1"}, "Table", JoinKind.LeftOuter),
#"Added Custom" = Table.AddColumn(#"Merged Queries", "Count", each if Table.RowCount([Table]) > 0 then [Table] else null),
#"Filled Down" = Table.FillDown(#"Added Custom",{"Count"}),
#"Added Custom1" = Table.AddColumn(#"Filled Down", "Custom", each if Table.RowCount([Table]) > 0 then [Table] else Table.ReplaceValue([Count],[Count]{0}[Date1],[Date],Replacer.ReplaceValue,{"Date1", "Date2"})),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Table", "Count"}),
#"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Date", "ISO Code", "Country"}, {"Date", "ISO Code", "Country"}),
#"Removed Columns1" = Table.RemoveColumns(#"Expanded Custom",{"Date"})
in
#"Removed Columns1"
你能让我知道我哪里做错了吗?