Forum Discussion
Anonymous
4 months agoNot applicable
DataFormat.Error: We couldn’t convert to Number in Power Query
In Power Query, I’m trying to change a column to Decimal_Number, but I keep getting this error "DataFormat.Error: We couldn't convert to Number"
The column looks like it has numbers, but some rows have things like "-" or blanks. How do I handle this cleanly without breaking my queries ?
Anonymous in Power Query, first replace bad values before changing type. Try the below M Code and see if that helps.
= Table.ReplaceValue( PreviousStep, "-", null, Replacer.ReplaceValue, {"YourColumn"} )
3 Replies
- Jai-RathinavelSuper User
Anonymous in Power Query, first replace bad values before changing type. Try the below M Code and see if that helps.
= Table.ReplaceValue( PreviousStep, "-", null, Replacer.ReplaceValue, {"YourColumn"} ) - AhmedxSuper User
to know how to do this watch my video
https://1drv.ms/v/c/2d55b2fd1e600be2/IQAidihM5BB0RbuJaQCv0JBdAUHlqdrayHd8wgKAZmP7_6g?e=z2AwEO - ZanquetaSuper User
Hi Anonymous
My suggestion is to consider a defensive approach that prevents the query from failing even when the column contains unexpected characters such as hyphens or blanks. Power Query allows this through thetry ... otherwiseconstruct, which safely handles conversion errors.Create a New Column with Safe Numeric Conversion= try Number.From([YourColumn]) otherwise null