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
Creative_tree88
Helper III
Helper III

Change date with today's date

Hi all - this si doing my head in.  I have a column called 'Event Date'.  When there's no event registered, our system uses 01/01/2099 in place of just a null.  I'm using dates to calculate performance but I need something in the cell to calculate with - if I used 01/01/2099 our metrics would look very odd!!

How can I replace all instances of 01/01/2099 with today's date??  I've tried numerous suggestions offered in other message boards, but none of them seem to work.  It's almost as if Power BI doesn't recognise the format or something??

Really appreciate your help.  Thanks all.

2 ACCEPTED SOLUTIONS
danextian
Super User
Super User

Hi @Creative_tree88 ,

 

Below is a sample M query. What it does is  it replaces 1/1/2099  which is #date(2099,1,1) with the current date.  What you need to do is replace that date with any other date but in the formula bar, change the replace-to value to Date.From( DateTime.LocalNow())

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("zdCxDcAgEEPRXagj5WwCyc2C2H8NKNL8TBDJzeu+PEYJnXsO1zKPTZOVvMhGdvImHzJBBckqsUqsEqvEKrFKrBKrxCqzyp+vXmaC/31yLg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type",#date(2099, 1, 1),Date.From( DateTime.LocalNow()),Replacer.ReplaceValue,{"Date"})
in
    #"Replaced Value"

 

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

You need to use "ISBLANK" in the IF formula

Column = IF(ISBLANK('Performance Table'[Date Reported]),TODAY(),'Performance Table'[Date Reported])

 

Joel_Cami_0-1703161775308.png

 

View solution in original post

7 REPLIES 7
v-shex-msft
Community Support
Community Support

Hi @Creative_tree88 ,

Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information and description to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
danextian
Super User
Super User

Hi @Creative_tree88 ,

 

Below is a sample M query. What it does is  it replaces 1/1/2099  which is #date(2099,1,1) with the current date.  What you need to do is replace that date with any other date but in the formula bar, change the replace-to value to Date.From( DateTime.LocalNow())

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("zdCxDcAgEEPRXagj5WwCyc2C2H8NKNL8TBDJzeu+PEYJnXsO1zKPTZOVvMhGdvImHzJBBckqsUqsEqvEKrFKrBKrxCqzyp+vXmaC/31yLg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type",#date(2099, 1, 1),Date.From( DateTime.LocalNow()),Replacer.ReplaceValue,{"Date"})
in
    #"Replaced Value"

 

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi @danextian Many thanks.  I'm not sure how to translate that into an expression which works for my data?  My field is 'Event Date' and the table it's in is called "Performance Table".  Thank you.

Hi @Creative_tree88 ,

 

The M code is meant to be pasted to a blank query in the query editor. The resulting query will show you the steps.

danextian_0-1703154550803.png

Here is a video of what that code does.










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi @Creative_tree88 If you do it with DAX instead of using M within Power Query, as you said @danextian, you can create a conditional column with DAX

Joel_Cami_0-1703154191471.png

@Syndicate_Admin - thank you.  That worked.  How can I change this formula for another column where there are just blank cells if no date.  I need it to show today's date if there is a blank cell.  Table is called 'Performance Table' and field is 'Date Reported'.

 

Many thanks!

You need to use "ISBLANK" in the IF formula

Column = IF(ISBLANK('Performance Table'[Date Reported]),TODAY(),'Performance Table'[Date Reported])

 

Joel_Cami_0-1703161775308.png

 

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.