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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
PPStar
Helper V
Helper V

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

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

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

Anonymous
Not applicable

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

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.