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
ctedesco3307
Resolver II
Resolver II

Replace just the time value for some not all records in in date time field

Hello- I need a way to replace time on records that are not 12:00. Some of the records load with 12:00 AM as the time and some do not. For the ones that are not 12:00 AM, I want to replace the time on there with 12:00 AM.  I don't want to split up the date and time into seperate columns.

 

Any thoughts? thank you - in advance 

ctedesco3307_0-1655405750815.png

 

1 ACCEPTED SOLUTION
tackytechtom
Super User
Super User

Hi @ctedesco3307 ,

 

Before:

tomfox_0-1655408924593.png

 

 

After:

tomfox_1-1655408939621.png

 

 

Here the code in advanced editor:

tomfox_2-1655408992962.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDJSMDCwAiOlWJ1oJSOsosYwUUMjK2NTmKgJXNTUytDcytAELGoKN8HcysACiMCiZpjmxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [datetime = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"datetime", type datetime}}),
    #"Replace Values" = Table.ReplaceValue(#"Changed Type",each [datetime], each Date.From([datetime]) & Time.FromText("00:00:00") ,Replacer.ReplaceValue,{"datetime"})

in
    #"Replace Values"

 

Let me know if this solves your issue 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

1 REPLY 1
tackytechtom
Super User
Super User

Hi @ctedesco3307 ,

 

Before:

tomfox_0-1655408924593.png

 

 

After:

tomfox_1-1655408939621.png

 

 

Here the code in advanced editor:

tomfox_2-1655408992962.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDJSMDCwAiOlWJ1oJSOsosYwUUMjK2NTmKgJXNTUytDcytAELGoKN8HcysACiMCiZpjmxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [datetime = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"datetime", type datetime}}),
    #"Replace Values" = Table.ReplaceValue(#"Changed Type",each [datetime], each Date.From([datetime]) & Time.FromText("00:00:00") ,Replacer.ReplaceValue,{"datetime"})

in
    #"Replace Values"

 

Let me know if this solves your issue 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

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.