Hi @powerbideveloper,
I have created the following function that, starting from a table, replaces the errors in the columns of type Number.
let fnReplaceErrorsofNumberValues = (inputTable as table) as table =>
let
TableSchemaCall = Table.Schema(inputTable),
FilteredRows = Table.SelectRows(TableSchemaCall, each ([TypeName] = "Number.Type")),
ToList = FilteredRows[Name],
SelectionOfColumns = Table.ColumnNames( Table.SelectColumns( inputTable, ToList ) ),
#"Converted to Table" = Table.FromList(SelectionOfColumns, Splitter.SplitByNothing(), null, null, ExtraValues.Ignore),
#"Added Custom" = Table.AddColumn(#"Converted to Table", "Custom", each 0),
#"Transposed Table" = Table.Transpose(#"Added Custom"),
ColList = Table.ToColumns(#"Transposed Table"),
#"Replaced Errors" = Table.ReplaceErrorValues(inputTable, ColList)
in
#"Replaced Errors",
Documentation = [
Documentation.Name = " fxReplaceErrorsofNumberValues",
Documentation.Description = " Given a table, replaces errors in columns of type numeric ",
Documentation.LongDescription = " Given a table, replaces errors in columns of type numeric ",
Documentation.Category = " Table",
Documentation.Version = " 1.00: full code review",
Documentation.Source = " local",
Documentation.Author = " José Antonio Fernández Puga"
]
in
Value.ReplaceType( fnReplaceErrorsofNumberValues, Value.ReplaceMetadata( Value.Type( fnReplaceErrorsofNumberValues ), Documentation ))
We apply this function in the Data_CallfxReplaceErrorsValues query, after the step in which we assign the data types to the columns.
let
Source = Excel.Workbook(File.Contents("C:\Enterprise DNA\Forum\Where to clean #DIV0, source or Power BI\Data.xlsx"), null, true),
Tabla1_Table = Source{[Item="Tabla1",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(Tabla1_Table,{{"Numerator", Int64.Type}, {"Denominator", Int64.Type}, {"Result", type number}, {"Result2", type number}}),
ReplaceErrors = fxReplaceErrorsofNumberValues(#"Changed Type")
in
ReplaceErrors
Regards,
Data.xlsx (9.7 KB)
CleanDiv0_JAFP.pbix (394.2 KB)