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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Transforming DATE data types

I have a dataset that does not recognize the calendar date format. My dataset is based on sales and only has the "Period/Year" as a date option. (period being the month it occured). So all my sales have a "Period/Year" associated with it but no actual date (ex: the 16th or the 31st). The format of the "Period/Year" looks like this "001/2024", "1" representing the month of January and year being 2024. 

 

Whenever I try to change the data type in the Power Query from Text to Date, it returns back "1/1/2024" which is not accurate to the sales. I tried to create a separate column by month and year and it still won't let me change it/

 

How can I create a DATE data type with just the month and year?

2 ACCEPTED SOLUTIONS
m_dekorte
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

A date data type in M classifies date values that's why a conversion yielded an actual date value, the 1st of the month. You can change its format but a month - year combination without a day component (which is no true date) will be of type text.

View solution in original post

collinsg
Super User
Super User

Good day jwasilko,

As your data does not include the day of month the best that can be done is to choose a day of the month to represent the month - for example the first day of each month or the last day of each month. If your requirement can be satisified by turning "001/2024" to 1st January 2024, "002/2024" to 1st February 2024 etc, then this code will solve the problem.

 

The approach is to

  • Transform the column, splitting each value at the "/" into a list of two items.
  • Transform the column once more, creating a date using the day of month as 1 and taking the month and year from the items in the list.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjAw1DcyMDJRitUBcYyQOcZQTiwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Month/Year" = _t]),
#"Split at slash" = Table.TransformColumns(Source, {{"Month/Year", each Text.Split(_,"/"), type text}}),
#"Convert to first of month" = Table.TransformColumns( #"Split at slash", {{"Month/Year", each #date(Number.From(_{1}), Number.From(_{0}),1), type date}} )
in
#"Convert to first of month"

 This will turn...

collinsg_0-1718952765014.png

into

collinsg_1-1718952779724.png

If you wished to use the end of the month rather than the start of month you could transform the column once more using Date.EndOfMonth.

Hope this helps.

 

View solution in original post

2 REPLIES 2
collinsg
Super User
Super User

Good day jwasilko,

As your data does not include the day of month the best that can be done is to choose a day of the month to represent the month - for example the first day of each month or the last day of each month. If your requirement can be satisified by turning "001/2024" to 1st January 2024, "002/2024" to 1st February 2024 etc, then this code will solve the problem.

 

The approach is to

  • Transform the column, splitting each value at the "/" into a list of two items.
  • Transform the column once more, creating a date using the day of month as 1 and taking the month and year from the items in the list.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjAw1DcyMDJRitUBcYyQOcZQTiwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Month/Year" = _t]),
#"Split at slash" = Table.TransformColumns(Source, {{"Month/Year", each Text.Split(_,"/"), type text}}),
#"Convert to first of month" = Table.TransformColumns( #"Split at slash", {{"Month/Year", each #date(Number.From(_{1}), Number.From(_{0}),1), type date}} )
in
#"Convert to first of month"

 This will turn...

collinsg_0-1718952765014.png

into

collinsg_1-1718952779724.png

If you wished to use the end of the month rather than the start of month you could transform the column once more using Date.EndOfMonth.

Hope this helps.

 

m_dekorte
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

A date data type in M classifies date values that's why a conversion yielded an actual date value, the 1st of the month. You can change its format but a month - year combination without a day component (which is no true date) will be of type text.

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.