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
E9067
Frequent Visitor

Creating Custom Function to Convert Text String to DateTime

Several columns within my data have datetime fromatted as a text string  yyyyMMddHHmm and I am trying to create a custom function to invoke while creating a new column that converts this string to MM-dd-yyyy HHmm; however, I have been unsuccessful. Any help would be appreciated. I am new to Power BI and Power Query Editor. I have tried the below without success.

 

let
ConvertTextToDate = (textDate as nullable text) =>
if textDate <> null then
DateTime.FromText(textDate, [Format="yyyyMMddHHmm"])
else
null
in
ConvertTextToDate

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @E9067 

You can refer to the following solution.

1.Create a blank query, and put your function code to the advanced editor.

2.In your original table, click the "Invoke Custom function" in Add Column

vxinruzhumsft_0-1703469543207.png

 

3.Select the function you have created in step1, in this sample the function name is 'Query1', and select the column in table you want to use the function.

vxinruzhumsft_1-1703469595580.png

4.Output

vxinruzhumsft_2-1703469649594.png

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @E9067 

You can refer to the following solution.

1.Create a blank query, and put your function code to the advanced editor.

2.In your original table, click the "Invoke Custom function" in Add Column

vxinruzhumsft_0-1703469543207.png

 

3.Select the function you have created in step1, in this sample the function name is 'Query1', and select the column in table you want to use the function.

vxinruzhumsft_1-1703469595580.png

4.Output

vxinruzhumsft_2-1703469649594.png

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

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 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.

Top Solution Authors