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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ContabilidadBI
Helper III
Helper III

Change years in a Date column in Query Editor

Hi!

 

I am working with an example database that in the fact table has a date column with years 1996, 1997 and 1998. How can I change the years of this date column to other years (for example 2005,2006 and 2007) in the Query Editor, maintaining the day and the month? I can do it in DAX, but I have been trying to do it with M for a while and I can't get it to work. Any ideas?

 

Thank you!!

1 ACCEPTED SOLUTION

Hi @ContabilidadBI 

You may delete the 'changed type' steps in Applied steps.Then use replace values as requested.At last,click 'detect date type' for the column.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQHQktLM6VYHRDHCMExgsiY4+RYgDnGcE4sAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [date = _t]),
    #"Replaced Value" = Table.ReplaceValue(Source,"1996","2005",Replacer.ReplaceText,{"date"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Replaced Value",{{"date", type date}})
in
    #"Changed Type"

Regards,

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-cherch-msft
Employee
Employee

Hi @ContabilidadBI 

You may try to use replace values to change them.

a1.png

Regards,

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-cherch-msft  thanks for your response,

 

That's what I tried but unfortunately it only changes it in the first day of the year:

Image 3.png

Thanks

Hi @ContabilidadBI 

You may delete the 'changed type' steps in Applied steps.Then use replace values as requested.At last,click 'detect date type' for the column.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQHQktLM6VYHRDHCMExgsiY4+RYgDnGcE4sAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [date = _t]),
    #"Replaced Value" = Table.ReplaceValue(Source,"1996","2005",Replacer.ReplaceText,{"date"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Replaced Value",{{"date", type date}})
in
    #"Changed Type"

Regards,

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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