Forum Discussion
TomJWhite
5 years agoFrequent Visitor
Extract part of string before specific character
Hi there, Im working with a Netflix dataset that has titles (column name [Title]) for shows like "Brooklyn Nine-Nine: Season 3: Greg and Larry (Episode 22)". For each entry, I want to check a...
- 5 years ago
TomJWhite Well, in Power Query you could split the column based on the : but there is also Text.BeforeDelimiter so you could do:
if [ContentType] = "TV" then Text.BeforeDelimiter([Title],":") else [Title]In DAX you would do something like:
Column = IF( [ContentType] = "TV", LEFT([Title],SEARCH(":",[Title])-1), [Title] )
Anonymous
5 years agoNot applicable
Hi TomJWhite
Yes, M is more intuitive for text munipulation. You need to observe the data, if it is always to extract the first ":" then it is simple
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcirKz8/OqcxT8MvMS9UFEVYKwamJxfl5CsZWCu5FqekKiXkpCj6JRUWVChquBZnF+SmpCkZGmkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.BeforeDelimiter([Column1],":"))
in
#"Added Custom"