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
David283
Helper I
Helper I

Problem converting dates from text, mixed formats in one column.

I have a table with a mix of date formats in one column.  Some are in the excel serial number format, and others are in a date/time/timezone format.  please see image below.

 

David283_0-1660938273151.png

 

 

I need to convert these into date only format.  I know how to use transfom and get the date only from the date/time/timezone ones, but I somehow need to fix the serial number ones first.  How can I go about this?

1 ACCEPTED SOLUTION
edhans
Super User
Super User

I would fix them in a few steps. You can do this 99% with the user interface and simple and easy to follow formulas.

  1. Create a new column with the following formula: if Text.Length([DateField]) = 5 then Number.FromText([DateField]) else null - this will return an integer.
  2. Now convert that to a date.
  3. Now another new column - if Text.End([DateField], 1) = "Z" then [DateField] else null - this will pull your time fields.
  4. Convert that to datetime.
  5. Now you have to get them to be both the same, either both date, datetime, or datetimezone. Convert them to the same, then one last column:
    1. if [FirstDate] = null then [SecondDate] else [FirstDate]
  6. Delete the temp first and second date, and the original date field.


Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

4 REPLIES 4
edhans
Super User
Super User

I would fix them in a few steps. You can do this 99% with the user interface and simple and easy to follow formulas.

  1. Create a new column with the following formula: if Text.Length([DateField]) = 5 then Number.FromText([DateField]) else null - this will return an integer.
  2. Now convert that to a date.
  3. Now another new column - if Text.End([DateField], 1) = "Z" then [DateField] else null - this will pull your time fields.
  4. Convert that to datetime.
  5. Now you have to get them to be both the same, either both date, datetime, or datetimezone. Convert them to the same, then one last column:
    1. if [FirstDate] = null then [SecondDate] else [FirstDate]
  6. Delete the temp first and second date, and the original date field.


Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

You had me all the way till step 6 🙂

 

I did steps 1 - 5 and it worked great, thank you! 

 

But step 6...  This is a power BI report and more data will roll in every day.  I plan to try to figure out and fix my source, but in the mean time, do I need to leave the conversion formulas and columns in place so that these automaticly convert each day?

No. Tomorrow when new data comes in, it will rerun all of these steps. It is just deleting those columns before it gets loaded to Power BI. Look at the steps that are being created on the right side of the Power Query window. Think of that as a macro. It isn't like Excel where it is permenantly deleting those columns. It only deletes the columns after steps 1-5 are done again.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Understood.

 

Marking solution, Thanks for the help!

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.

Top Solution Authors
Top Kudoed Authors