Forum Discussion
[DataFormat.Error] We couldn't convert to Number.
Download the latest version of Power BI Desktop and share us the code in The Advanced Editor.
- AnnaFenton8 years agoFrequent Visitor
Hi v-chuncz-msft,
Thank you for your reply. I pasted the code in Advanced Editor below. As you can see, I have trimmed the Country-ID column and converted it into whole number. The error still occurs when I click apply. Many thanks for your time in advance.
Kind regards,
Anna
let
Source = Table.Combine({#"Population-country-1950-1999", #"Population-country-2000-2049", #"Population-country-2050-2100"}),
#"Removed Columns" = Table.RemoveColumns(Source,{"AgeGrpStart", "AgeGrpSpan"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"LocID", "Country-ID"}, {"Location", "Country"}, {"Time", "Year"}, {"AgeGrp", "Age-Group"}, {"PopMale", "Population-Male"}, {"PopFemale", "Population-Female"}, {"PopTotal", "Population-Total"}}),
#"Replaced Value" = Table.ReplaceValue(#"Renamed Columns","9-May","5-9",Replacer.ReplaceText,{"Age-Group"}),
#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","14-Oct","10-14",Replacer.ReplaceText,{"Age-Group"}),
#"Changed Type" = Table.TransformColumnTypes(#"Replaced Value1",{{"Year", Int64.Type}, {"Population-Male", type number}, {"Population-Female", type number}, {"Population-Total", type number}}),
#"Removed Errors" = Table.RemoveRowsWithErrors(#"Changed Type", {"Country-ID"}),
#"Filtered Rows" = Table.SelectRows(#"Removed Errors", each ([#"Country-ID"] <> null)),
#"Changed Type1" = Table.TransformColumnTypes(#"Filtered Rows",{{"Country-ID", Int64.Type}}),
#"Filtered Rows1" = Table.SelectRows(#"Changed Type1", each true),
#"Changed Type2" = Table.TransformColumnTypes(#"Filtered Rows1",{{"Year", Int64.Type}}),
#"Filtered Rows2" = Table.SelectRows(#"Changed Type2", each true),
#"Removed Errors1" = Table.RemoveRowsWithErrors(#"Filtered Rows2", {"Population-Male"}),
#"Removed Errors2" = Table.RemoveRowsWithErrors(#"Removed Errors1", {"Population-Female"}),
#"Removed Errors3" = Table.RemoveRowsWithErrors(#"Removed Errors2", {"Population-Total"}),
#"Filtered Rows3" = Table.SelectRows(#"Removed Errors3", each ([#"Country-ID"] <> null and [#"Country-ID"] <> "")),
#"Removed Blank Rows" = Table.SelectRows(#"Filtered Rows3", each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))),
#"Filtered Rows4" = Table.SelectRows(#"Removed Blank Rows", each true),
#"Trimmed Text" = Table.TransformColumns(Table.TransformColumnTypes(#"Filtered Rows4", {{"Country-ID", type text}}, "en-GB"),{{"Country-ID", Text.Trim, type text}}),
#"Cleaned Text" = Table.TransformColumns(#"Trimmed Text",{{"Country-ID", Text.Clean, type text}}),
#"Changed Type3" = Table.TransformColumnTypes(#"Cleaned Text",{{"Country-ID", Int64.Type}}),
#"Filtered Rows5" = Table.SelectRows(#"Changed Type3", each true),
#"Trimmed Text1" = Table.TransformColumns(Table.TransformColumnTypes(#"Filtered Rows5", {{"Country-ID", type text}}, "en-GB"),{{"Country-ID", Text.Trim, type text}}),
#"Filtered Rows6" = Table.SelectRows(#"Trimmed Text1", each true),
#"Replaced Value2" = Table.ReplaceValue(#"Filtered Rows6","",null,Replacer.ReplaceValue,{"Country-ID"}),
#"Changed Type4" = Table.TransformColumnTypes(#"Replaced Value2",{{"Country-ID", Int64.Type}})
in
#"Changed Type4"