In this Power BI article, we will learn how to check if text is Date using the Power Query editor with different examples in Power BI.
Power Query Check If Text is Date
Let us see how to check if the text is date using the Power Query editor in Power BI.
Example :1
In this example, we will use the below Vehicles table data as a data source to check if the text is date and then returns the true value or else a false value in Power BI.
Open the Power Bi desktop and load the data into it, and under the Home, tab selects the transform data option as shown below: It will automatically redirect to the Power Query editor.
Now in the power query editor, you can see that the released date column data is presented with the text data type and date data type value as highlighted below:
Add a custom column by selecting Add Column-> Custom column check if the text is date or not as highlighted below:
In the custom column pop-up window, enter the new column name and add the below-mentioned formula and click on the ok button.
=try Value.Is(Date.From([Released Date]),type date) otherwise false
In the below screenshot, you can see that the custom column displays the result value as true for the text data type and for the date data type it displays the false value.
= Table.AddColumn(#"Changed Type", "Custom", each try Value.Is(Date.From([Released Date]),type date) otherwise false)
- Change the text data type to date data type by selecting Home -> Data type and selecting date data type, now we can see for the date data type displays the true value, and the text data type displays an error.
- In the same way, the custom column displays the result value as true for the date data type, and for the text data type, it displays the false value.
= Table.TransformColumnTypes(#"Added Custom",{{"Released Date", type date}})
This is how to check if the text is date using the Power Query editor in Power BI.
Example:2
In this example, we will use the below-mentioned bikes table data for the different scenarios to check if the text is Date in Power BI.
- Load the data source into the Power BI desktop, and select Home -> Transform data it will automatically redirect to the Power Query editor.
- Now in the power query editor, you can see that the released date column data is presented with the text data type and date data type value as shown below:
- Select Add Column-> Custom column to check if the text is date or not as highlighted below:
- In the custom column pop-up window, enter the new column name and add the below-mentioned formula and click on the ok button.
if([Released Date] is date) then [Released Date] else null
In the below screenshot, you can see that the custom column displays null values for the text data type.
= Table.AddColumn(#"Changed Type", "Custom", each if([Released Date] is date) then [Released Date] else null)
- Change the text data type to date data type by selecting Home -> Data type, and choose the date data type now we can see for the date data type displays the date value else it displays the null value,
- In the same way, the custom column displays the null value and date value based on the condition applied.
= Table.AddColumn(#"Removed Columns", "Custom", each if([Released Date] is date) then [Released Date] else null)
This is how to check if the text is date using the Power Query editor in Power BI.
In this Power BI article, we have learned how to check if text is Date using the Power Query editor with different examples in Power BI.
You may like the following Power BI tutorials:
- Power Query Add Column Date
- Power Query Add Column If Statement
- How to add a column with a dropdown list in Power Query
- How to duplicate multiple columns using Power Query
- Power Query Add Column
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com