Forum Discussion
Powerquery: replace blanks and dates in past with a future date
- 4 years ago
Hi Anonymous
I think your forecast date is probably a date not a datetime. Which mean the comparing it to DateTime.FixedLocalNow() will not work (they need matching datatypes. You could solve this with a Date.From function you could also get both steps in one.#"Replace Value" = Table.ReplaceValue( #"Table1_Table", each [Forecast], each if [Forecast] < Date.From(DateTime.FixedLocalNow()) or [Forecast] = null then #date(2022, 12, 31) else [Forecast], Replacer.ReplaceValue, {"Forecast"} )
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
Best regards,
Jeroen - Anonymous4 years ago
Many thanks Jeroen, your advice to introduce a Date.From function worked. I kept my steps seperate in the end as it was a simple fix.
#"Replaced Value" = Table.ReplaceValue(#"Changed Type",null,#date(2021, 12, 31),Replacer.ReplaceValue,{"Forecast"}),
#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value",each[Forecast],each if [Forecast] < Date.From(DateTime.FixedLocalNow()) then #date(2022,12,30) else [Forecast],Replacer.ReplaceValue,{"Forecast"}),Regards
Matt
Hi Anonymous
I think your forecast date is probably a date not a datetime. Which mean the comparing it to DateTime.FixedLocalNow() will not work (they need matching datatypes. You could solve this with a Date.From function you could also get both steps in one.
#"Replace Value" = Table.ReplaceValue(
#"Table1_Table",
each [Forecast],
each
if [Forecast] < Date.From(DateTime.FixedLocalNow()) or [Forecast] = null then
#date(2022, 12, 31)
else
[Forecast],
Replacer.ReplaceValue,
{"Forecast"}
)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
Best regards,
Jeroen
Many thanks Jeroen, your advice to introduce a Date.From function worked. I kept my steps seperate in the end as it was a simple fix.
#"Replaced Value" = Table.ReplaceValue(#"Changed Type",null,#date(2021, 12, 31),Replacer.ReplaceValue,{"Forecast"}),
#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value",each[Forecast],each if [Forecast] < Date.From(DateTime.FixedLocalNow()) then #date(2022,12,30) else [Forecast],Replacer.ReplaceValue,{"Forecast"}),
Regards
Matt