Forum Discussion
Find dates in text
- 4 years ago
Use this in a custom column
= List.Max(List.Transform(List.Transform(Text.Split(Text.Replace(Text.Replace(Text.Replace(Text.Replace([Data],".","/"),".","/"),"*","/"),"-"," ")," "),(x)=>Text.Select(x,{"0".."9","/"})),(y)=>if Text.Contains(y,"/") then try Date.From(y) otherwise null else null))Full code for testing
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hY/BbsMgEER/ZZVTGzUxBhts5VOsHMCwCQRjN+A2/vsSN1XV9tDjzL4Z7XTd5lX1UZuq7jWQck/4nhJKYQcsi/ouGPQRBzM6prXZHF+6jXc4ovKHCDVoqeWPIG2/ct5MowugFc4WBbSkaQPgo2KcHBqLFQJhO1I9MhQmG6K2s8qXK67o5MK7Bi+jZDJ/CqUoyqYoW7gMaEd04WpPquYr28uIEQ2r8JTO6Qq02RK6XUdEfdLnxAWPn60+zFy4YOf70pLuaQW3rNS8cKEu/rBSQ3Dnt1RzsajgM1iUtFjflEOcpY2Ki6YlK/okQ4J0S8/ASMGLzGRngWSy9Wvyf4u/q9q/TccP", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]), #"Added Custom" = Table.AddColumn(Source, "Custom", each List.Max(List.Transform(List.Transform(Text.Split(Text.Replace(Text.Replace(Text.Replace(Text.Replace([Data],".","/"),".","/"),"*","/"),"-"," ")," "),(x)=>Text.Select(x,{"0".."9","/"})),(y)=>if Text.Contains(y,"/") then try Date.From(y) otherwise null else null))) in #"Added Custom"
Hi severm ,
Here a potential solution. You can merge some of the steps. But it might help you anyway or at least gets you closer to a soluition:
Before:
After:
Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZY3BDYAwDANXiXhWtHFcKGUWxBY8GJ+CQJTy9PkSL0u37ZvAAlIgSPESSxjPEKV03dpfTq28RiUIosdwF6xPxSZFVps/kNmBrp05142BQwPVqL+/EZr0YesB", 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}}),
#"Replaced Value" = Table.ReplaceValue(#"Changed Type",".","/",Replacer.ReplaceText,{"Column1"}),
#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","txt","",Replacer.ReplaceText,{"Column1"}),
#"Replaced Value2" = Table.ReplaceValue(#"Replaced Value1","*","/",Replacer.ReplaceText,{"Column1"}),
#"Replaced Value3" = Table.ReplaceValue(#"Replaced Value2"," ","",Replacer.ReplaceText,{"Column1"}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Replaced Value3", "Column1", Splitter.SplitTextByDelimiter("-", QuoteStyle.Csv), {"Column1.1", "Column1.2"}),
#"Added Custom" = Table.AddColumn(#"Split Column by Delimiter", "Custom", each if [Column1.2] <> null then [Column1.2] else [Column1.1]),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", type date}})
in
#"Changed Type1"
Let me know if this helps or if you get stuck somewhere 🙂
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/
- severm4 years agoFrequent Visitor
Hey Tom,
I very much appreciate your answer. As always, the real life is more complex :). txt in my description are full senteces or abreviation, shorter or longer, sometimes txt includes also numbers.
qbcsde45cd 01.06.2022 - 31.05.2023 csfmeoj3dde ljfofbl;s 5 dada 01.06.2022 -31.05.2023lepojn dbfuif7 9089n fe lopjfeif4f 03-04.05.2022 pinsdiubf4frf pjnwd lasa3asde 17/18/19 kmfiofjnrigb56 casfsfe34fgthtr 28*02*2023 sdgdht676s plnu67jniu 31.12.24 xniubuy67bkl; mnjhvt567ybnl 31/12/2022 amsuaisb67890 (ant txt) 30/6/22 (any text) This why I proposed some steps in my post. If you could help put me on a new direction I would be grateful.
Thank you!