简体   繁体   English

Excel Power Query 合并和转换列

[英]Excel Power Query Merge and Transform columns

I am trying to combine 2 columns into one and then replace "Null" rows with the value in an adjacent columns using Excel Power Query.我正在尝试将 2 列合并为一列,然后使用 Excel Power Query 将“空”行替换为相邻列中的值。 SO far I haven't been able to resolve this issue.到目前为止,我还无法解决此问题。 These are my unsuccessful attempts:这些是我不成功的尝试:

Attempt 1:尝试1:

= Table.ExpandTableColumn(Source, "F 52 AGR_1016", {"AGR_NAME"}, {"F 52 AGR_1016.AGR_NAME"}),
 else Table.ReplaceValue(Source, each "", Replacer.ReplaceValue{"New value of line"})

Attempt 2:尝试2:

= Table.ExpandTableColumn(Source, "F 52 AGR_1016", {"AGR_NAME"}, {"F 52 AGR_1016.AGR_NAME"}), 
if #"F 52 AGR_1016" = "" then Replacer.ReplaceValue("","",{"New Value of line"}), else

I get the following error message, however Excel does not show me where exactly that error is:我收到以下错误消息,但是 Excel 没有显示该错误的确切位置:

Expression.SyntaxError: Token Eof expected. Expression.SyntaxError:应为令牌 Eof。

It is a bit hard to tell what you are doing, and the code format is incorrect.很难说你在做什么,而且代码格式不正确。 You can't append if then to Table.ExpandTableColumn你不能 append如果然后Table.ExpandTableColumn

To merge two column: click select them, right click, then choose merge columns要合并两列:单击 select 它们,右键单击,然后选择合并列

To add a column that tests other column values, add column.. custom column... and use = if xxx then yyy else zzz要添加测试其他列值的列,请添加列..自定义列...并使用 = if xxx then yyy else zzz

= if [Col1] = null then [Col2] else [Col3]

This code expands three columns;此代码扩展了三列; merges the text value of Column1 and Column2 into a new column called Merged;将 Column1 和 Column2 的文本值合并到一个名为 Merged 的新列中; creates Column4 where the result is Merge if Column3 is a null, and Column3 if Column3 is not a null创建 Column4,如果 Column3 是 null,则结果为 Merge,如果 Column3 不是 null,则创建 Column3

...
#"Expanded" = Table.ExpandTableColumn(Source, "AllRows", {"Column1", "Column2", "Column3"}, {"Column1", "Column2", "Column3"}),
#"Merged Columns" = Table.CombineColumns(#"Expanded",{"Column2", "Column1"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Merged"),
#"Added Custom" = Table.AddColumn(#"Merged Columns", "Custom4", each if [Column3]=null then [Merged] else [Column3])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM