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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Anonymous
Not applicable

Transform text column to Date

Hi,

I power Query I have a text column YearMonth and I want to convert this to a date column. I can do this by creating a custom column but how can I do this by Transforming the column as I don't want to add another column and changing the type to date afterwards.
Here is my custom column.

 

= Table.AddColumn(#"Added Items", "Date", each Date.FromText(Text.Range([yearMonth], 0,4) & "-"  & Text.Range([yearMonth], 4,2)))

 

 

1 ACCEPTED SOLUTION
ronrsnfld
Super User
Super User

Try

    #"Transform to Dates" = Table.TransformColumns(#"Previous Step", {
        {"yearMonth", each 
            let 
                parts = Splitter.SplitTextByLengths({4,2})(_),
                partsN = List.Transform(parts, each Number.From(_))
            in 
                #date(partsN{0},partsN{1},1),
                type date
                }})

View solution in original post

2 REPLIES 2
ronrsnfld
Super User
Super User

Try

    #"Transform to Dates" = Table.TransformColumns(#"Previous Step", {
        {"yearMonth", each 
            let 
                parts = Splitter.SplitTextByLengths({4,2})(_),
                partsN = List.Transform(parts, each Number.From(_))
            in 
                #date(partsN{0},partsN{1},1),
                type date
                }})
PhilipTreacy
Super User
Super User

Hi @Anonymous 

 

If your YearMonth is of the form 202403 then you can't change the type to date by transforming the column to date type.

 

Reason being, there's no delimiter to indicate the year and month.  If you had 2024-03 then you could do this.  With the day being assumed to be the 1st.

 

So you can add a new column and then convert that.  That's not such a big issue is it?

 

regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

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.

Top Kudoed Authors