Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
philerob2014
Frequent Visitor

Timestamp when true

Hey Everyone,

 

I need some help. Essentially, I am trying to timestamp a record once the conditions are true.

 

If

Condition 1 = true

and

condition 2 = true

date/timestamp

else

leavel empty

 

Any ideas how I can do this? 

1 ACCEPTED SOLUTION
tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi @philerob2014 ,

 

Maybe like this?

Before:

tackytechtom_0-1670870312468.png

 

After:

tackytechtom_1-1670870332012.png

 

I applied the following logic:

if [Substate] = "Pending return" and [timestamp] <> null then [timestamp] else if [Substate] = "Pending return" and [timestamp] = null then DateTime.LocalNow() else if [Substate] <> "Pending return" and [timestamp] <> null then null else null

 

Here the full code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkjNS8nMS1coSi0pLcpT0lEyMjAy0jU00jUwUzA0sjIwACKlWJ1opbTEnOJUNHlDLPJgDoapuERjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Substate = _t, timestamp = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Substate", type text}, {"timestamp", type datetime}}),
    #"Replace Values" = Table.ReplaceValue(#"Changed Type",each [timestamp],each if [Substate] = "Pending return" and [timestamp] <> null then [timestamp] else if [Substate] = "Pending return" and [timestamp] = null then DateTime.LocalNow() else if [Substate] <> "Pending return" and [timestamp] <> null then null else null, Replacer.ReplaceValue,{"timestamp"})

in
    #"Replace Values"

 

/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

9 REPLIES 9
philerob2014
Frequent Visitor

This worked beautifully @tackytechtom  to fix the first of 2 problems, thanks! But I think I may be out of luck on rounding the solution out for my reporting.

 

Problem 1 : Get a timestamp when condition is true (SOLVED)

Problem 2: If the row already has a timestamp from the previous refresh and is still true, leave it. If its no longer true, make it blank again. 

 

Do you have any idea if ill be able to do that? I see that I cant with a table column outside of power query editor, so I cant just make another column and make it take the date if one already exists, or to make a new one. 

tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi @philerob2014 ,

 

Ok, I think I now understand a bit better what you are after. For your scenario I suggest you use Power Query:

 

Before:

tackytechtom_0-1670359129383.png

 

After:

tackytechtom_1-1670359149690.png

 

I applied the following logic:

if [Column] = true and [timestamp] <> null then [timestamp] else if [Column] = true and [timestamp] = null then DateTime.LocalNow() else if [Column] = false and [timestamp] <> null then null else null

 

Here the code for the advanced editor:

tackytechtom_2-1670359274448.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKikqTVXSUTIyMDLSNTTSNTBTMDSyMjAAIqVYnWiltMScYnR5QyzyYA7ULFR2LAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column = _t, timestamp = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column", type logical}, {"timestamp", type datetime}}),
    #"Replace Values" = Table.ReplaceValue(#"Changed Type",each [timestamp],each if [Column] = true and [timestamp] <> null then [timestamp] else if [Column] = true and [timestamp] = null then DateTime.LocalNow() else if [Column] = false and [timestamp] <> null then null else null, Replacer.ReplaceValue,{"timestamp"})

in
    #"Replace Values"

 

In case you haven't worked with Power Query before, I'd suggest to start with a blank query and look into the steps above. I am sure you will be able to figure it out how to align your code 🙂 Otherwise, you could also just create a new column with the if logic above. If you are happy with it and you want to overwrite your timestamp column, I'd suggest to check out this blog post, where you can learn how to substitute values (instead of creating a new column)



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 

Ahhhh, you are brilliant! But what would be my referenced field for "[timestamp]". That was created outside of power query editor so I didn't think the second step could reference that. @tackytechtom 

tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi @philerob2014 ,

 

I interpreted "Problem 2: If the row already has a timestamp from the previous refresh and is still true, leave it. If its no longer true, make it blank again."  that there is already a timestamp column in place. I might have misunderstood your query. 

 

You miight wantt to provide some example data and expected result?

 

/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 

Sure, let me clarify exactly what I need so its clear. Your solutions are beautifully written, I just dont understand how to connect them.

 

If [Substate] = "Pending return" 

     get original time and date that this condition was first true on report refresh. Purge date when condition is not true. If condition is true over multiple refreshes, keep the original date.

tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi @philerob2014 ,

 

Maybe like this?

Before:

tackytechtom_0-1670870312468.png

 

After:

tackytechtom_1-1670870332012.png

 

I applied the following logic:

if [Substate] = "Pending return" and [timestamp] <> null then [timestamp] else if [Substate] = "Pending return" and [timestamp] = null then DateTime.LocalNow() else if [Substate] <> "Pending return" and [timestamp] <> null then null else null

 

Here the full code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkjNS8nMS1coSi0pLcpT0lEyMjAy0jU00jUwUzA0sjIwACKlWJ1opbTEnOJUNHlDLPJgDoapuERjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Substate = _t, timestamp = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Substate", type text}, {"timestamp", type datetime}}),
    #"Replace Values" = Table.ReplaceValue(#"Changed Type",each [timestamp],each if [Substate] = "Pending return" and [timestamp] <> null then [timestamp] else if [Substate] = "Pending return" and [timestamp] = null then DateTime.LocalNow() else if [Substate] <> "Pending return" and [timestamp] <> null then null else null, Replacer.ReplaceValue,{"timestamp"})

in
    #"Replace Values"

 

/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 

@tackytechtom  Ok, I see what you are heading towards. I am lost on one thing to make this work, because when I place the code, it gives me an error. Is it because that I am using your code without first creating a "timestamp" column first that it can reference? I am under the assumption that we would have to create 2 columns in total the refer to the substate column. 1 to grab the timestamp, and the second to identify the earliest date in which the condition was true. 

 

Is your code design for just 1 total column or the 2 that I thought we would have to use? 

tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi @philerob2014 ¨,

 

My approach is just using one column and expected that column to be in place already.

 

/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 

tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi @philerob2014 ,

 

I reckon with timestamp you mean the current timestamp?

 

Here a solution in DAX with a calculated column:

tackytechtom_0-1670266954434.png

 

timestampcol = IF ( 'Table'[column] = TRUE, NOW(), BLANK() )

 

I am not sure though, whether this is what you were looking for 🙂

 

Let me know!

 

/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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.