导入数据后替换所有列的所有错误值(同时保留行)
Replace all error values of all columns after importing datas (while keeping the rows)
作为数据源的Excel table可能包含错误值(#NA,#DIV/0),这可能会在稍后的[=11=中的转换过程中干扰某些步骤].
根据以下步骤,我们可能不会得到任何输出但会出现错误。那么如何处理这种情况呢?
我在 Power Query 中找到了两个标准步骤来捕获它们:
- Remove errors (UI: Home/Remove Rows/Remove 错误) -> 所有有错误的行将被删除
- Replace error values (UI: Transform/Replace 错误) -> 必须首先选择列来执行此操作。
第一种可能性对我来说不是解决方案,因为我想保留行并只替换错误值。
在我的例子中,我的数据 table 会随着时间的推移而改变,这意味着列名可能会改变(例如年份),或者出现新的列。所以第二种可能太静态了,因为我不想每次都改变脚本。
所以我试图获得一种动态的方式来清理所有列,独立于列名(和列数)。它用空值替换错误。
let
Source = Excel.CurrentWorkbook(){[Name="Tabelle1"]}[Content],
//Remove errors of all columns of the data source. ColumnName doesn't play any role
Cols = Table.ColumnNames(Source),
ColumnListWithParameter = Table.FromColumns({Cols, List.Repeat({""}, List.Count(Cols))}, {"ColName" as text, "ErrorHandling" as text}),
ParameterList = Table.ToRows(ColumnListWithParameter ),
ReplaceErrorSource = Table.ReplaceErrorValues(Source, ParameterList)
in
ReplaceErrorSource
这里是三个不同的查询消息,在我向源添加了两个新列(有错误)之后:
如果有人有其他解决方案来进行这种数据清理,请在此处写下您的post。
let
src = Excel.CurrentWorkbook(){[Name="Tabelle1"]}[Content],
cols = Table.ColumnNames(src),
replace = Table.ReplaceErrorValues(src, List.Transform(cols, each {_, "!"}))
in
replace
作为数据源的Excel table可能包含错误值(#NA,#DIV/0),这可能会在稍后的[=11=中的转换过程中干扰某些步骤].
根据以下步骤,我们可能不会得到任何输出但会出现错误。那么如何处理这种情况呢?
我在 Power Query 中找到了两个标准步骤来捕获它们:
- Remove errors (UI: Home/Remove Rows/Remove 错误) -> 所有有错误的行将被删除
- Replace error values (UI: Transform/Replace 错误) -> 必须首先选择列来执行此操作。
第一种可能性对我来说不是解决方案,因为我想保留行并只替换错误值。
在我的例子中,我的数据 table 会随着时间的推移而改变,这意味着列名可能会改变(例如年份),或者出现新的列。所以第二种可能太静态了,因为我不想每次都改变脚本。
所以我试图获得一种动态的方式来清理所有列,独立于列名(和列数)。它用空值替换错误。
let
Source = Excel.CurrentWorkbook(){[Name="Tabelle1"]}[Content],
//Remove errors of all columns of the data source. ColumnName doesn't play any role
Cols = Table.ColumnNames(Source),
ColumnListWithParameter = Table.FromColumns({Cols, List.Repeat({""}, List.Count(Cols))}, {"ColName" as text, "ErrorHandling" as text}),
ParameterList = Table.ToRows(ColumnListWithParameter ),
ReplaceErrorSource = Table.ReplaceErrorValues(Source, ParameterList)
in
ReplaceErrorSource
这里是三个不同的查询消息,在我向源添加了两个新列(有错误)之后:
如果有人有其他解决方案来进行这种数据清理,请在此处写下您的post。
let
src = Excel.CurrentWorkbook(){[Name="Tabelle1"]}[Content],
cols = Table.ColumnNames(src),
replace = Table.ReplaceErrorValues(src, List.Transform(cols, each {_, "!"}))
in
replace