Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
ok_kpop
Frequent Visitor

Extract Date from Middle of Text in Column

I have a column name called "Folder Path" which contains the following text:

 

\\test\testfolder\\test subfolder\DATA ABC Month-end Reports\2016 December\A

\\test\testfolder\\test subfolder\DATA ABC Month-end Reports\2016 March\A

\\test\testfolder\\test subfolder\DATA ABC Month-end Reports\2013 May\B

\\test\testfolder\\test subfolder\DATA ABC Month-end Reports\2023 August\C

 

Is there a way I can extract the year and month (highlighted in red) from each line into a new column so I can format them into a date format? 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WigGCktTiEgiZlp+TkloEE1MoLk2Cibg4hjgqODo5K/jm55Vk6KbmpSgEpRbkF5UUx8QYGRiaKbikJqfmJoGUOirF6lDRYN/EouQMKptqDDS1MibGiYpmGhkrOJaml4KMcVaKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Folder Path" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Date", each Date.From(Text.Split([Folder Path],"\"){7} & " 1"),type date)
in
    #"Added Custom"

 

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.

View solution in original post

1 REPLY 1
lbendlin
Super User
Super User

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WigGCktTiEgiZlp+TkloEE1MoLk2Cibg4hjgqODo5K/jm55Vk6KbmpSgEpRbkF5UUx8QYGRiaKbikJqfmJoGUOirF6lDRYN/EouQMKptqDDS1MibGiYpmGhkrOJaml4KMcVaKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Folder Path" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Date", each Date.From(Text.Split([Folder Path],"\"){7} & " 1"),type date)
in
    #"Added Custom"

 

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.