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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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