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.

V-lianl-msft

Convert to date type in different formats in the "Date" column

Scenario

We may face the following situation when importing data to Power BI:

From the data source, the whole column is in the right date format.

Once being imported into Power BI, the column will have dates in two formats as below:

Mon 16/11/20 throws an error.

3/15/2021 indicates the correct format.

Through this blog, I will show you how to use Power Query and DAX to convert different date types into unified format.

 

Table used: 

Table used.png

Expected result: 

Table used2.png

In the Power Query: 

  1. Right click the Date column to split column by delimiter. Then specify the space as the delimiter.

IN the PQ1.png

In the PQ2.png

In the PQ3.png

  1. Right click the Date.2 column and add as new query. Then change the new query to a table. Remove the blank rows.

6.png

7.png

8.png

9.png

  

  1. Change the type as follows.

10.png

11.png

12.png

  1. In the original table, change the Date column to Date type, then remove errors and remove Date.2 column.

13.png

14.png

15.png

  1. Use the Append operation to combine two tables into a single table. Then add column from two columns (Hold Ctrl and select two columns at the same time). The Date column is date type. You can remove the Date.1 and Column1 columns and keep the Date column.

16.png

17.png

18.png19.png20.png

21.png

22.png

 

Tips:  

For more information about Append operation, please refer to this blog.

 

DAX Query Operation: 

  1. Create a calculated column. The New Date column is date type.

 

New Date =

VAR col1 =

IF ( LEN ( [Date] ) > 10, DATEVALUE ( RIGHT ( [Date], 8 ) ) )

VAR col2 =

IF ( LEN ( [Date] ) <= 10, [Date] )

RETURN

IF ( ISBLANK ( col1 ), DATEVALUE ( col2 ), col1 )

23.png

 

Please check the attached files for details. 

 

Author: Stephen Tao

Reviewer: Icey Zhang& Liang Lu