Fix inconsistent and weird date formatting in a column in PowerBI

Carrie E 1 Reputation point
2021-03-26T01:05:58.057+00:00

In PowerBI, I am trying to clean up some incoming data to follow consistent formatting.

I have a column which has a text string meant to represent date and time. The format of the data from the source changed over time, so the data is in one of two formats.

Within the "StartDate" Column, some values look like this:
YYYY-MM-DD HH:MM:SS AMPM (Example: 2021-03-25 05:48:12 PM)

Others look like this:
ddd mmm d HH:MM:SS YYYY (Example: Thu Mar 25 17:48:12 2021)

My goal is to end up with two columns like this:
"Start Date" column ... format: YYYY-MM-DD (Example: 2021-03-25)
"Start Time" column ... format (24 hour): HH:MM:SS (Example: 17:48:12)

In plain explanation of steps, I was thinking I need to do something like:

  1. If data starts with numbers, then translate to the Date = first 11 characters in format of MM/DD/YYYY ... Time = last 12 characters in HH:MM:SS AMPM format
  2. If data doesn't start with numbers, then cut off the first 4 characters (day of week), move the last 4 characters (the year) to the beginning, and then translate to the Date = first 11 characters in format of YYYY mmm d ... Time = last 8 characters in HH:MM:SS format
  3. if source is blank = leave as null

Thanks in advance for helping a newbie!

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,182 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Herbert Seidenberg 1,191 Reputation points
    2021-03-27T00:33:06.43+00:00

  2. Herbert Seidenberg 1,191 Reputation points
    2021-03-31T02:06:13.253+00:00

    PQ works the same in Excel and PowerBI.