Forum Discussion

severm's avatar
severm
Frequent Visitor
4 years ago
Solved

Find dates in text

Dear all,   I kindly request the help of this community. I am a beginner and I am still getting acustom with Language M and DAX.   In the file I have I need to extract the maximum dates from a te...
  • Vijay_A_Verma's avatar
    Vijay_A_Verma
    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"