我的问题也涉及Excel和Power BI的查询编辑器。如何从报表的特定单元格中获取值,并将其填充为具有该值的新列。假设我们有一个像这样的平面文件的源,在单元格B2中有一个特定的值:
以便将新列添加到表中,并使用特定值的单元格B2填充该列。
答案 0 :(得分:1)
在查询编辑器中,在“主页”上,单击“高级编辑器”并粘贴以下代码:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WckksSVXSUTIyMLTQNTDUNTQEcpRidaKVQDSU6VZUmllSDOQ55+fkF8FEEwsKckBai1JTYEIFOaW5QHZZZn5OaglMMDkjtaioEshLzkksggrHAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
#"Removed Columns" = Table.RemoveColumns(Source,{"Column3"}),
#"Removed Top Rows" = Table.Skip(#"Removed Columns",2),
#"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]),
GetValueFromCell = #"Removed Columns"{0} [Column2],
#"Added Custom" = Table.AddColumn(#"Promoted Headers", "NewColumnName", each GetValueFromCell)
in
#"Added Custom"
这里的关键步骤是:
GetValueFromCell = #"Removed Columns"{0} [Column2],
其中{0}表示从Column2的第一行获取值,{1}表示第二行,依此类推。
#"Added Custom" = Table.AddColumn(#"Promoted Headers", "NewColumnName", each GetValueFromCell),
Matt Allington的这篇文章非常有帮助https://exceleratorbi.com.au/convert-a-cell-value-into-a-column-with-power-query