cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

Change the date if it is before today

Hi all!  This is my first post and I hope you can help me. I have the following problem to solve. I have this date column and my goal is that if the date in the "Fecha" (date) column is less than today, the value is replaced by today. If the date is equal to today or greater than the date is kept. This is in PowerQuery

PowerBI.png

 

Thanks you all!
Regards
Bruno Bentancor.-

1 ACCEPTED SOLUTION
Super User III
Super User III

Hi @brunobentancor

You can create a custom column with code like this:

if [Fecha] >= Date.From(DateTime.LocalNow()) then [Fecha]  else Date.From(DateTime.LocalNow())  

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

3 REPLIES 3
Super User III
Super User III

Hello @brunobentancor 

 

if you want to avoid to multiple columns handling, you can transform the existing one

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjTVMzTQMzJQitUBciyQOMYGSBwDQz0DS2SOBZgTCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Fecha = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Fecha", type date, "de-DE"}}),
    TransformFecha = Table.TransformColumns
    (
        #"Changed Type",
        {
            {
                "Fecha",
                each if _ >= Date.From(DateTime.LocalNow()) then _ else Date.From(DateTime.LocalNow())
            }
        }
    )
in
    TransformFecha

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Super User III
Super User III

Hi @brunobentancor

You can create a custom column with code like this:

if [Fecha] >= Date.From(DateTime.LocalNow()) then [Fecha]  else Date.From(DateTime.LocalNow())  

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

Excellent @AlB ! Thank you very much for your help 😄
It worked for me! 

Regards!
Bruno Bentancor.-

Helpful resources

Announcements
secondImage

Happy New Year from Power BI

This is a must watch for a message from Power BI!

December Update

Check it Out!

Click here to read more about the December 2020 Updates!

Community Blog

Check it Out!

Click here to read the latest blog and learn more about contributing to the Power BI blog!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors
Top Kudoed Authors