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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
prabhatnath
Advocate III
Advocate III

Converting Text Column (Some record with AM/PM and some without) to DateTime Issue

HI I have imported a SharePoint List and facing issues to convert the column to DateTime as few records are with AM or PM but few does not have AM or PM at all.

 

The rows that are not having AM or PM are of dd/MM/yy hh:mm (24Hr) format but the one with AM or PM are in MM/dd/yyyy hh:mm tt format.

 

Please suggest what will be the best way to convert these columns to DateTime so that it work for future imports too?

 

Here is how the SP List looks like:

prabhatnath_0-1706209238097.png

 

Here is how the Imported Data Looks like.

prabhatnath_1-1706209263484.png

EDIT: (Added Sample Data)

IdStartTimeEndTime
120/12/2023 10:3320/12/2023 10:43
220/12/2023 11:1020/12/2023 11:19
323/01/2024 13:3223/01/2024 13:34
423/01/2024 13:3723/01/2024 13:39
523/01/2024 13:4723/01/2024 13:55
61/25/2024 10:03 AM1/25/2024 10:17 AM
71/25/2024 10:23 AM1/25/2024 11:02 AM
81/25/2024 11:17 AM1/25/2024 11:25 AM
91/25/2024 9:04 AM1/25/2024 9:31 AM

 

 

Thanks,

Prabhat

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @prabhatnath ,

 

Modify formula like below:

StandardizedStartTime1 =
VAR OriginalStartTime = Table1[StartTime]
VAR IsAM =
    CONTAINSSTRING ( OriginalStartTime, "AM" )
VAR IsPM =
    CONTAINSSTRING ( OriginalStartTime, "PM" )
VAR TimePart =
    TIMEVALUE ( FORMAT ( Table1[StartTime], "HH:mm" ) )
VAR HourPart =
    HOUR ( TIMEVALUE ( FORMAT ( TimePart, "HH:mm" ) ) )
RETURN
    IF (
        OR ( IsAM, IsPM ),
        OriginalStartTime,
        IF ( HourPart > 12, OriginalStartTime & " PM", OriginalStartTime & " AM" )
    )

vkongfanfmsft_0-1706601238695.png

 

Best Regards,
Adamk Kong

 

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

5 REPLIES 5
Anonymous
Not applicable

Hi @prabhatnath ,

 

You can create below formula:

 

start_ = 
IF (
    CONTAINSSTRING ( Table1[StartTime], "AM" ),
    Table1[StartTime],
    IF(CONTAINSSTRING ( Table1[StartTime], "PM" ),
    Table1[StartTime],
    Table1[StartTime] & " " & "AM"
))

 

vkongfanfmsft_1-1706515403936.png

 

Best Regards,
Adamk Kong

 

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

Thank you @Anonymous this will help add AM to the missed ones but if you see the hours in the missed one are in 24Hr format so appending AM may not help. As we cant convert the new column to DateTime type. Any suggestion here?

Thanks,

Prabhat

Anonymous
Not applicable

Hi @prabhatnath ,

 

Modify formula like below:

StandardizedStartTime1 =
VAR OriginalStartTime = Table1[StartTime]
VAR IsAM =
    CONTAINSSTRING ( OriginalStartTime, "AM" )
VAR IsPM =
    CONTAINSSTRING ( OriginalStartTime, "PM" )
VAR TimePart =
    TIMEVALUE ( FORMAT ( Table1[StartTime], "HH:mm" ) )
VAR HourPart =
    HOUR ( TIMEVALUE ( FORMAT ( TimePart, "HH:mm" ) ) )
RETURN
    IF (
        OR ( IsAM, IsPM ),
        OriginalStartTime,
        IF ( HourPart > 12, OriginalStartTime & " PM", OriginalStartTime & " AM" )
    )

vkongfanfmsft_0-1706601238695.png

 

Best Regards,
Adamk Kong

 

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

PijushRoy
Super User
Super User

Hi @prabhatnath 

Please use LOCALE option in Power Query editor to fix the DateTime issue
If needed, You can remove word AM/PM by using REPLACE (replace the AM or PM as blank) before using LOCALE function 
https://www.myonlinetraininghub.com/change-type-using-locale-with-power-query

 


If your requirement is solved, please make sure to MARK AS SOLUTION ✔️ and help other users find the solution quickly. Please hit the LIKE 👍 button if this comment helps you.

Thanks
Pijush
www.MyAccountingTricks.com 
https://www.youtube.com/MyAccountingTricks

 




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





If we see the rows that are not having AM or PM are of dd/MM/yy hh:mm (24Hr) format but the one with AM or PM are in different format like MM/dd/yyyy hh:mm tt.

 

I have added sampel data to the main question post for easy.

 

Also I get erro like culture not supported, so not sure what is the current culture used to save this.

 

LOCALE option in Power Query editor did not help

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.