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
Anonymous
Not applicable

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
AlB
Super User
Super User

Hi @Anonymous

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
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

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

AlB
Super User
Super User

Hi @Anonymous

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

Anonymous
Not applicable

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

Regards!
Bruno Bentancor.-

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.

Top Solution Authors
Top Kudoed Authors