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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
Super User
Super User

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
Super User
Super User

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors