Forum Discussion
OLE DB or ODBC error: [DataFormat.Error] We couldn't convert to Number..
- 1 year ago
I have a doubt with this part:
{"CRace_CEth_Combined_Broad", type text}, "ComboRegionName", "Age Group"it may not able to correctly specify types for "ComboRegionName" and "Age Group", which might be leading Power BI to guess a default type (likely type number) for one or both columns.
So even though you later remove these columns, the error might occur before that removal if something earlier (like column type inference or a cached schema) tries to validate the whole table before applying transforms.
Try to modify the "Changed Type" step to properly define the types for all columns:
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{ {"PIN", type text}, {"Date", type date}, {"Time", type time}, {"Zipcode", Int64.Type}, {"Age", Int64.Type}, {"Sex", type text}, {"Hospital", type text}, {"CRace_CEth_Combined_Broad", type text}, {"ComboRegionName", type text}, {"Age Group", type text} }),
I think the error only appears after deduplication likely because that’s when Power BI tries to load and materialize the data into the model.
Deduplicating with Table.Distinct doesn’t itself coerce types but if the underlying data has unexpected values or nulls, the type transformations applied before or after could fail during the final load.Some improvements for your code :
each if [Zipcode] = null or [Zipcode] = "" then "A" else [Zipcode]
or better:each if [Zipcode] = null then "A" else Text.From([Zipcode])
Or even better:each if [Zipcode] = null then "A" else [Zipcode], type text
I have a doubt with this part:
{"CRace_CEth_Combined_Broad", type text}, "ComboRegionName", "Age Group"
it may not able to correctly specify types for "ComboRegionName" and "Age Group", which might be leading Power BI to guess a default type (likely type number) for one or both columns.
So even though you later remove these columns, the error might occur before that removal if something earlier (like column type inference or a cached schema) tries to validate the whole table before applying transforms.
Try to modify the "Changed Type" step to properly define the types for all columns:
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{
{"PIN", type text},
{"Date", type date},
{"Time", type time},
{"Zipcode", Int64.Type},
{"Age", Int64.Type},
{"Sex", type text},
{"Hospital", type text},
{"CRace_CEth_Combined_Broad", type text},
{"ComboRegionName", type text},
{"Age Group", type text}
}),
I think the error only appears after deduplication likely because that’s when Power BI tries to load and materialize the data into the model.
Deduplicating with Table.Distinct doesn’t itself coerce types but if the underlying data has unexpected values or nulls, the type transformations applied before or after could fail during the final load.
Some improvements for your code :
each if [Zipcode] = null or [Zipcode] = "" then "A" else [Zipcode]
or better:
each if [Zipcode] = null then "A" else Text.From([Zipcode])
Or even better:
each if [Zipcode] = null then "A" else [Zipcode], type text
- ksheth1 year agoHelper I
Hi Amira,
Thank you for your response. I ended up just deleting the step where PowerBI automatically Changed Types and instead manually assigned each variable's data type. That seems to have resolved my issue, but inherently it still seems weird to me that it was able to execute all the way through the first Remove Duplicate Rows step, but then had an issue in the second Remove Duplicate Rows step. Thank you for your suggestions on how to improve my code too, that was very helpful!
- v-kpoloju-msft1 year agoCommunity Support
Hi ksheth,
Thanks for the update. I'm glad to hear that manually assigning data types resolved your issue. Power BI’s automatic type detection can sometimes introduce unexpected behaviour, especially when working with diverse datasets. Your approach of explicitly defining each column's type is a great best practice to prevent similar issues in the future.
If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.
Thank you for using Microsoft Community Forum.