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
PPStar
Helper IV
Helper IV

Replace Today or Yesterday with today or yesterdays date

Hello

I have the following table

 

PPStar_0-1700480271328.png

 

Current, i am unable to change the data type of the column to DateTime, as the value with Today or Yesterday are not recognised as date. 

 

How can i replace the word Today with Today Date and yesterday with Yesterday's date. 

So i can change the data type to DateTime?

 

Thanks

 

1 ACCEPTED SOLUTION

Hi @PPStar ,

You can make a little adjustment base on the reply from @mh2587 ,please find details in the attachment.

=if Text.Contains([Start time], "Today") then
  DateTime.ToText(DateTime.LocalNow(), "yyyy-MM-dd") & Text.AfterDelimiter([Start time], ",")
else if Text.Contains([Start time], "Yesterday") then
  DateTime.ToText(DateTime.From(DateTime.LocalNow() - #duration(1, 0, 0, 0)), "yyyy-MM-dd")
    & Text.AfterDelimiter([Start time], ",")
else
  [Start time]

vyiruanmsft_0-1700721038749.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
mh2587
Super User
Super User

= if Text.Contains([YourColumnName], "Today") then DateTime.ToText(DateTime.LocalNow(), "yyyy-MM-dd")
  else if Text.Contains([YourColumnName], "Yesterday") then DateTime.ToText(DateTime.From(DateTime.LocalNow() - #duration(1, 0, 0, 0)), "yyyy-MM-dd")
  else [YourColumnName]

Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



Hello, this almost works. 

The only issue is the time. I thikn using the dd/MM/yyyy HH:MM:ss shows todays date and todays time, but i need it to show the time on the table

 

E.g if you look at the 2nd row, it says Today, 07:00 . So the new column shows it as 20/11/2023 12:11:11, where 12:11:11 is the Hour, Minute Second NOW. 

 

Any ideas?

 

Thanks

Hi @PPStar ,

You can make a little adjustment base on the reply from @mh2587 ,please find details in the attachment.

=if Text.Contains([Start time], "Today") then
  DateTime.ToText(DateTime.LocalNow(), "yyyy-MM-dd") & Text.AfterDelimiter([Start time], ",")
else if Text.Contains([Start time], "Yesterday") then
  DateTime.ToText(DateTime.From(DateTime.LocalNow() - #duration(1, 0, 0, 0)), "yyyy-MM-dd")
    & Text.AfterDelimiter([Start time], ",")
else
  [Start time]

vyiruanmsft_0-1700721038749.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.