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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Validate if value(String) is a date or not using M Language

Hi 

 

I am tryingto cretae this on the PawerQuery editor, use M Language, to evaluate if a value, or string if we can call it a string, is either valid date value or not.  I was aiming to use a Custom Column to indicate the outcome if True, yes it is a date, or False opposite.  Now when I import my data its takes on the 'ChangeType' as ABC123, if I set the format to date I basically create errors for rows with text rather than a date, exampe are 'n/a' or other words/text or sorts.   I have tried Value.IS([field] Number.Type) ist not doing it.  I dont wish to overwrite the orginal values I just need to indicate/test if it is date or not.

 

Screenshot 2022-03-22 144943.png

2 ACCEPTED SOLUTIONS
artemus
Microsoft Employee
Microsoft Employee

Your function would look like:

try Date.FromText([DateColumn]) <> null otherwise false

View solution in original post

Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

You will need to use complete formula alongwith try to suppress the error.  Don't omit try.....

 

=try Value.Is(Date.From([Date Field]), type date) otherwise false

If you want to convert it to date in a custom column

try Date.From([Date Field]) otherwise null

View solution in original post

6 REPLIES 6
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Use this (replace Date Field appropriately)

=try Value.Is(Date.From([Date Field]), type date) otherwise false

If you want to convert it to date in a custom column

try Date.From([Date Field]) otherwise null

 

Anonymous
Not applicable

Hi 

formula...Value.Is(Date.From([Date Field]), type date)

This is partially working,  however if the value is random text, I get am error in that row.  I may need need rethink the solution.

 

Chris

Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

You will need to use complete formula alongwith try to suppress the error.  Don't omit try.....

 

=try Value.Is(Date.From([Date Field]), type date) otherwise false

If you want to convert it to date in a custom column

try Date.From([Date Field]) otherwise null

Anonymous
Not applicable

Perfect, I now see how this works, yes it is working great and gives me a good starting point, thanks for the advice.

artemus
Microsoft Employee
Microsoft Employee

Your function would look like:

try Date.FromText([DateColumn]) <> null otherwise false

Anonymous
Not applicable

Hi

 

Did not work for my situation but handhy to have options, thanks.

 

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.