Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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?
Solved! Go to Solution.
Hi @mburkett ,
Suppose we have:
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.
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
Hi @mburkett ,
Suppose we have:
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.
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
@mburkett
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 19 | |
| 10 | |
| 9 | |
| 8 | |
| 7 |