powerbi - 按另一列中指示的数字多次重复 Power BI 中的行
问题描述
我遇到的问题的想法是,在 Power BI 中,我有一个如下表:
col1 col2
entry1 1
entry2 2
entry3 1
我想创建一个表格:
col1
entry1
entry2
entry2
entry3
也就是说,您按不同列中指定的数字复制每一行。在我的实际情况下,我的表还有许多其他列,其值也应该在每一行中重复。
我希望能够使用电源查询来做到这一点。
谢谢
解决方案
您可以使用公式将自定义列添加到表中
List.Repeat( { [col1] }, [col2] )
这会在每一行中生成一个包含列表的列,其中列表的元素被[col1]
列出[col2]
了很多次。
从那里,您可以使用表格上的按钮将该列表展开为行。
完整的 M 代码如下所示:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSs0rKao0VNJRMlSK1YFyjYBcIwTXGCIbCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [col1 = _t, col2 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"col1", type text}, {"col2", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Repeat({[col1]},[col2])),
#"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom")
in
#"Expanded Custom"
从这里,您可以选择col1
或Custom
删除其他列(如果您选择)。
推荐阅读
- javascript - 计算机在井字游戏 React.js 中移动到总是随机的空单元格?
- ms-access - MS Access 在不存在的地方插入
- c++ - 在 C++ 中使用迭代器修改数组元素
- php - 致命错误:未捕获错误:调用 /usr/share/php/Composer/Json/JsonFile.php:153 中未定义的函数 Composer\Json\json_decode()
- rest - 如何在不实际执行的情况下对 HTTP DELETE 操作的后果进行建模
- android - CoordinatorLayout + FrameLayout + ViewPager + RecyclerView
- apache-camel - 如何在骆驼的属性文件sql查询中传递标头值
- c# - Parallel.ForEach 中的异常日志
- node.js - 使用 V8 引擎调试 js 字节码
- javascript - 在 ComponentDidMount 中停止和启动 setInterval