Forum Discussion

ABC11's avatar
ABC11
Resolver I
1 year ago
Solved

Extract Date from Text in Column

Hello,

In power Query- I would like to extract date from Source.Name column  in Lasest date column.

Please help me here

 

Source.NameLastest Date
HZN All Last 7 - AM - 10-27-2024 05_31 AM10/27/2024
HZN All Last 7 - AM - 10-28-2024 05_31 AM10/28/2024
HZN All Last 7 - AM - 10-29-2024 05_31 AM10/29/2024
HZN All Last 7 - AM - 10-30-2024 05_31 AM10/30/2024
HZN All Last 7 - AM - 10-31-2024 05_31 AM10/31/2024
HZN All Last 7 - AM-2024-11-1211/12/2024
HZN All Last 7 - AM-2024-11-1311/13/2024
HZN All Last 7 - AM-2024-11-1411/14/2024
HZN All Last 7 - AM-2024-11-1511/15/2024
HZN All Last 7 - AM-2024-11-1611/16/2024
HZN All Last 7 - AM-2024-11-1711/17/2024
HZN All Last 7 - AM-2024-11-1811/18/2024
HZN All Last 7 - AM-2024-11-1911/19/2024

Thanks

ABC11

  • ABC11's avatar
    ABC11
    1 year ago

    Hello Omid_Motamedise,

    It working but when I click Table. All other column disappear. what would be the solution?

    Please

    Thanks

     

5 Replies

  • Easy enough,

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lcoxDoAgDEDRqzTMNmkLCIxuDuoBJMS4s+n9I/EAVpY//LyczbxvMNUKy3ndEABhWluYUAIKiQPyh+V2TRm+dOzSqUdb6tL8T78KmZFFJ1YnTideJ6NOgk6iTpIp5QE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Source.Name = _t]),
        #"Extracted Date" = Table.AddColumn(Source, "Date", each Date.From(Text.BetweenDelimiters([Source.Name],"-"," ",1,1)))
    in
        #"Extracted Date"

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    ABC11 Here is one way:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdI7CsMwDIDhqwjPMdbDju0xW4a0B2gIpXu29v40KSpZjNGiQXz/JK2rmx93mPYdltf7Axk8TLdjEHrOnpEjYHoKHVs3OMLAOZxbtw29tDTTYklrM62GVLCVClpSaqbUTX+JJ/LEp6dAbPSiXow+qo9Gn9Qnox/Vj0af1fd/4fJFff8BLl/V/6++fQE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Source.Name = _t, #"Lastest Date" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Source.Name", type text}, {"Lastest Date", type date}}),
        #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Source.Name", Splitter.SplitTextByDelimiter("AM - ", QuoteStyle.Csv), {"Source.Name.1", "Source.Name.2"}),
        #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Source.Name.1", type text}, {"Source.Name.2", type text}}),
        #"Split Column by Delimiter1" = Table.SplitColumn(#"Changed Type1", "Source.Name.1", Splitter.SplitTextByDelimiter("AM-", QuoteStyle.Csv), {"Source.Name.1.1", "Source.Name.1.2"}),
        #"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"Source.Name.1.1", type text}, {"Source.Name.1.2", type date}}),
        #"Split Column by Delimiter2" = Table.SplitColumn(#"Changed Type2", "Source.Name.2", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, false), {"Source.Name.2.1", "Source.Name.2.2"}),
        #"Changed Type3" = Table.TransformColumnTypes(#"Split Column by Delimiter2",{{"Source.Name.2.1", type date}, {"Source.Name.2.2", type text}}),
        #"Removed Columns" = Table.RemoveColumns(#"Changed Type3",{"Lastest Date"}),
        #"Added Custom" = Table.AddColumn(#"Removed Columns", "Latest Date", each if [Source.Name.2.1] = null then [Source.Name.1.2] else [Source.Name.2.1]),
        #"Removed Columns1" = Table.RemoveColumns(#"Added Custom",{"Source.Name.1.2", "Source.Name.2.1", "Source.Name.2.2"})
    in
        #"Removed Columns1"
  • ABC11's avatar
    ABC11
    Resolver I

    Hello Greg,

    Its didn't worked becuase it remove my whole data set.

    I have really big data set with 48 column and thousands of row- all those data disappear.

    Thanks

    Please

  • Hi ABC11 

     

    Check this solution

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lcoxDoAgDEDRqzTMNmkLCIxuDuoBJMS4s+n9I/EAVpY//LyczbxvMNUKy3ndEABhWluYUAIKiQPyh+V2TRm+dOzSqUdb6tL8T78KmZFFJ1YnTideJ6NOgk6iTpIp5QE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ource.Name = _t]),
        #"Added Custom" = Table.AddColumn(Source, "Custom", each List.RemoveNulls(List.Transform(Text.Split([ource.Name]," "), (x)=> try Date.From(Text.Replace(x,"AM-","")) otherwise null)){0})
    in
        #"Added Custom"
    • ABC11's avatar
      ABC11
      Resolver I

      Hello Omid_Motamedise,

      It working but when I click Table. All other column disappear. what would be the solution?

      Please

      Thanks