admin管理员组文章数量:1421751
I have a PowerQuery flow in Excel that needs to work on a number of dynamic column headings - so far not to much of a challenge but I now need to deal with a variable number of columns. Basically I am pivoting some data by month and want to have this increase each month.
As part of this step I need to replace the Nulls with 0 so I can do some further calculations but since the number of columns will increase I can not just use my current approach of referencing the column number as that will grow over time.
Is anyone able to nudge me the right way on this on how to deal with X columns. My current replace code is below:
= Table.ReplaceValue(#"Pivoted Column",
null, 0,
Replacer.ReplaceValue,
{Table.ColumnNames(#"Pivoted Column"){2},
Table.ColumnNames(#"Pivoted Column"){3},
Table.ColumnNames(#"Pivoted Column"){4},
Table.ColumnNames(#"Pivoted Column"){5}})
The next challenge will be that I then need to add in a repeating calculation of one column to the next again which will grow each month so that I can show the size of change between each month....
I have a PowerQuery flow in Excel that needs to work on a number of dynamic column headings - so far not to much of a challenge but I now need to deal with a variable number of columns. Basically I am pivoting some data by month and want to have this increase each month.
As part of this step I need to replace the Nulls with 0 so I can do some further calculations but since the number of columns will increase I can not just use my current approach of referencing the column number as that will grow over time.
Is anyone able to nudge me the right way on this on how to deal with X columns. My current replace code is below:
= Table.ReplaceValue(#"Pivoted Column",
null, 0,
Replacer.ReplaceValue,
{Table.ColumnNames(#"Pivoted Column"){2},
Table.ColumnNames(#"Pivoted Column"){3},
Table.ColumnNames(#"Pivoted Column"){4},
Table.ColumnNames(#"Pivoted Column"){5}})
The next challenge will be that I then need to add in a repeating calculation of one column to the next again which will grow each month so that I can show the size of change between each month....
Share Improve this question asked Jan 17 at 17:42 user3644997user3644997 991 gold badge1 silver badge10 bronze badges 1- So this has a few things. If you're pivoting a column into individual columns, you may be able to make the replacement at that stage so when it pivots into columns it won't have duplicates. I imagine the count of your columns are dynamic because you're pivoting another column. – Mark S. Commented Jan 17 at 18:50
2 Answers
Reset to default 1try creating a transform them applying it against all the columns.
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
Columns = Table.ColumnNames(#"Source"),
Fix = List.Transform(Columns,(x)=>{x, each _ ?? 0, type number}),
Transform = Table.TransformColumns(Source, Fix)
in Transform
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlLSgWOlWJ1oJRgbRIH4RtgE4JqQVUCMiAUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", Int64.Type}, {"Column3", Int64.Type}, {"Column4", Int64.Type}}),
Cols = Table.ColumnNames(#"Changed Type"),
Transformed = List.Accumulate(Cols, #"Changed Type", (s,c) => Table.TransformColumns(s, {c, each _ ?? 0}))
in
Transformed
Try to tweak the step "Cols" to pick columns to transform.
本文标签: excelPowerqueryDynamic column number replaceStack Overflow
版权声明:本文标题:excel - Powerquery - Dynamic column number replace - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745351615a2654800.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论