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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
joshua1990
Post Prodigy
Post Prodigy

Extract DateTime from YYYYMMDDHHMMSS

Hi experts!

I have a calumn of that format:

DateTime
202201311529530000
202201311829530000
000000
000000

 

Now I would like to transform that into this:

DateTime
31.01.2022 15:29:53
31.01.2022 18:29:53
 
 

 

How is this possible ussing Power Query? 

Since there are a lot of columns with that kind of format I would like to use the solution as a function.

2 ACCEPTED SOLUTIONS
AlB
Community Champion
Community Champion

A possible solution (ignoring those last 4 zeros)

Place the following M code in a blank query to see the steps.

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMjIwNDY0NDWyNDU2AAKlWB0kYQsUYQMDDGYsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [DateTime = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each if [DateTime]= "000000" then null else #datetime(Number.From(Text.Start([DateTime], 4)), Number.From(Text.Middle([DateTime], 4,2)), Number.From(Text.Middle([DateTime], 6,2)), Number.From(Text.Middle([DateTime], 8,2)),Number.From(Text.Middle([DateTime], 10,2)), Number.From(Text.Middle([DateTime], 12,2))), type datetime),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"DateTime"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "DateTime"}})
in
    #"Renamed Columns"

 

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

View solution in original post

AlB
Community Champion
Community Champion

@joshua1990 

You could use a function like this and create a custom column using the function to do the conversion, then delete the original column. See it all at work in the attached file.

(input_ as text) => 
if input_= "000000" then null else #datetime(Number.From(Text.Start(input_, 4)), Number.From(Text.Middle(input_, 4,2)), Number.From(Text.Middle(input_, 6,2)), Number.From(Text.Middle(input_, 8,2)),Number.From(Text.Middle(input_, 10,2)), Number.From(Text.Middle(input_, 12,2)))

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

View solution in original post

4 REPLIES 4
AlB
Community Champion
Community Champion

@joshua1990 

You could use a function like this and create a custom column using the function to do the conversion, then delete the original column. See it all at work in the attached file.

(input_ as text) => 
if input_= "000000" then null else #datetime(Number.From(Text.Start(input_, 4)), Number.From(Text.Middle(input_, 4,2)), Number.From(Text.Middle(input_, 6,2)), Number.From(Text.Middle(input_, 8,2)),Number.From(Text.Middle(input_, 10,2)), Number.From(Text.Middle(input_, 12,2)))

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

AlB
Community Champion
Community Champion

A possible solution (ignoring those last 4 zeros)

Place the following M code in a blank query to see the steps.

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMjIwNDY0NDWyNDU2AAKlWB0kYQsUYQMDDGYsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [DateTime = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each if [DateTime]= "000000" then null else #datetime(Number.From(Text.Start([DateTime], 4)), Number.From(Text.Middle([DateTime], 4,2)), Number.From(Text.Middle([DateTime], 6,2)), Number.From(Text.Middle([DateTime], 8,2)),Number.From(Text.Middle([DateTime], 10,2)), Number.From(Text.Middle([DateTime], 12,2))), type datetime),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"DateTime"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "DateTime"}})
in
    #"Renamed Columns"

 

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

 @AlB : THanks a lot! It works perfectly well. How can I switch this into a individual function / query? I would like to use this functionn for multiple columns

AlB
Community Champion
Community Champion

Hi @joshua1990 

Are the last four zeros to be ignored? If not, please show an example in which those positions are not zero with the expected output

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.