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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
mburkett
New Member

Date Transformation

I am pulling in a table from the web with only the day and month. Power query is guessing the date and setting everything to 2023. Is there a way to tell it to change to 2022 if the date is greater than today's date?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @mburkett ,

 

Suppose we have:

vcgaomsft_0-1673232844973.png

Please follow these steps:

1. Duplicated [Date] Column:

2. Change [Date - Copy]'s Type from [Date] to [Date/Time]

3. Add a custom column:

if [#"Date - Copy"] > DateTime.LocalNow()
then Date.AddYears([Date],-1)
else [Date]

4. Remove and rename columns.

vcgaomsft_1-1673232997904.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc65DQAgDAPAXaiRwAnvLCj7r4EokOzyujsnoaBYNU+RH4zhjMbojMGYjMXYDFSRHCAJyALSwH/EBQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Date", "Date - Copy"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Duplicated Column",{{"Date - Copy", type datetime}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each if [#"Date - Copy"] > DateTime.LocalNow()
then Date.AddYears([Date],-1)
else [Date]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Date", "Date - Copy"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Date"}})
in
    #"Renamed Columns"

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @mburkett ,

 

Suppose we have:

vcgaomsft_0-1673232844973.png

Please follow these steps:

1. Duplicated [Date] Column:

2. Change [Date - Copy]'s Type from [Date] to [Date/Time]

3. Add a custom column:

if [#"Date - Copy"] > DateTime.LocalNow()
then Date.AddYears([Date],-1)
else [Date]

4. Remove and rename columns.

vcgaomsft_1-1673232997904.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc65DQAgDAPAXaiRwAnvLCj7r4EokOzyujsnoaBYNU+RH4zhjMbojMGYjMXYDFSRHCAJyALSwH/EBQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Date", "Date - Copy"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Duplicated Column",{{"Date - Copy", type datetime}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each if [#"Date - Copy"] > DateTime.LocalNow()
then Date.AddYears([Date],-1)
else [Date]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Date", "Date - Copy"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Date"}})
in
    #"Renamed Columns"

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Mahesh0016
Super User
Super User

@mburkett 
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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 Solution Authors