Forum Discussion
Replace Blank or Nulls based on Column Type
- 4 years ago
Create a list of Transforms depending on the column types, then apply that.
For example, if you wanted to apply your above transformations to every column in a table of those data types, you could use:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Ncw7EoAgFEPRvaSmUfGzlzevEBEsGDr2b8yM1T1pYoYTARM8GIhZSNQiXZTQR2u08u3MEaWbWqVCbf+TWoldeqgD7i8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]), #"Replaced Value" = Table.ReplaceValue(Source,"null",null,Replacer.ReplaceValue,{"Column1"}), #"Previous Step" = Table.TransformColumnTypes(#"Replaced Value",{{"Column1", type text}, {"Column2", Int64.Type}}), //Use this part below in your code // changing #"Previous Step" to whatever your previous step is xFormList = List.Transform( Table.SelectRows(Table.Schema(#"Previous Step"), each [TypeName]="Text.Type")[Name], (L)=>{L, each if _ = "" or _ = null then "NA" else _, type text}) & List.Transform( Table.SelectRows(Table.Schema(#"Previous Step"), each [TypeName]="Int64.Type")[Name],(L)=>{L, each if _ = "" or _ = null then 0 else _, Int64.Type}), replaceM = Table.TransformColumns(#"Previous Step", xFormList) in replaceM
Create a list of Transforms depending on the column types, then apply that.
For example, if you wanted to apply your above transformations to every column in a table of those data types, you could use:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Ncw7EoAgFEPRvaSmUfGzlzevEBEsGDr2b8yM1T1pYoYTARM8GIhZSNQiXZTQR2u08u3MEaWbWqVCbf+TWoldeqgD7i8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
#"Replaced Value" = Table.ReplaceValue(Source,"null",null,Replacer.ReplaceValue,{"Column1"}),
#"Previous Step" = Table.TransformColumnTypes(#"Replaced Value",{{"Column1", type text}, {"Column2", Int64.Type}}),
//Use this part below in your code
// changing #"Previous Step" to whatever your previous step is
xFormList =
List.Transform(
Table.SelectRows(Table.Schema(#"Previous Step"),
each [TypeName]="Text.Type")[Name], (L)=>{L, each if _ = "" or _ = null then "NA" else _, type text}) &
List.Transform(
Table.SelectRows(Table.Schema(#"Previous Step"),
each [TypeName]="Int64.Type")[Name],(L)=>{L, each if _ = "" or _ = null then 0 else _, Int64.Type}),
replaceM = Table.TransformColumns(#"Previous Step", xFormList)
in
replaceM
Thank you! This worked perfectly, but when I try to apply the changes, I'm getting this error message. I've confirmed that all the data types match what was in the previous step so this is weird.
- ronrsnfld4 years ago
Super User
Can you possibly upload a file that demonstrates the problem?
- nancyvangrrr4 years agoFrequent Visitor
Never mind. I found out what my issue was. The data types in Service weren't matching what was in Desktop. After matching the data types, it worked! Thank you!