Forum Discussion
JamieMcFadden
4 years agoRegular Visitor
Reading to a new table only the text values
Hi all! I have a table containing numeric values in some cells, and character values in other cells (as well as some cells that are blank and have null values). I show a simple example below. I...
- 4 years ago
You can do a single column like this:
Table.TransformColumns( Source, {{"Col1", each if (try Number.FromText(_) otherwise null) = null then _ else null, type text }})To transform all of the columns, we can make it more dynamic as follows:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8i9KN1TSUTIFYmcXIKEUqwMWNAKyDQ1AAjpKBjBBYyDH0QlIGBlA1MfGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Entity = _t, Col1 = _t, Col2 = _t, Col3 = _t]), fn_num2null = (txt) => if Value.Is(try Number.FromText(txt) otherwise null, Number.Type) or Text.Length(txt) = 0 then null else txt, TransformList = List.Transform(Table.ColumnNames(Source), each {_, fn_num2null, type text}), #"Transformed Columns" = Table.TransformColumns(Source, TransformList) in #"Transformed Columns"
AlexisOlson
Super User
4 years agoYou can do a single column like this:
Table.TransformColumns(
Source,
{{"Col1",
each if (try Number.FromText(_) otherwise null) = null then _ else null,
type text
}})
To transform all of the columns, we can make it more dynamic as follows:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8i9KN1TSUTIFYmcXIKEUqwMWNAKyDQ1AAjpKBjBBYyDH0QlIGBlA1MfGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Entity = _t, Col1 = _t, Col2 = _t, Col3 = _t]),
fn_num2null = (txt) => if Value.Is(try Number.FromText(txt) otherwise null, Number.Type) or Text.Length(txt) = 0 then null else txt,
TransformList = List.Transform(Table.ColumnNames(Source), each {_, fn_num2null, type text}),
#"Transformed Columns" = Table.TransformColumns(Source, TransformList)
in
#"Transformed Columns"