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.

Reply
NirH_at_BITeam
Frequent Visitor

Convert DateTime into Date in Query Editor using M function

Hi,

 

I'm looking for the right function to replace a DateTime to a Date in M.
The challenge is that the DateTime length may vary based on month and day number, so for example I have: 8/5/2017 12:00:00 AM OR 10/21/2019 12:00:00 AM

 

In both cases I need to keep only the date without the time and change it to: "mm/dd/yyyy".

I used the split function but that requires 2-3 steps in query. Not a big deal but I’m after adding a custom column with the right M formula that will get me the right result.

 

Thanks!
NH

 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

This should help.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @NirH_at_BITeam 

 

Try wrapping the original DateTime data with the 'DateTime.Date()' function

Also, make sure the date you are referring to is actually a date and not a string

 

For example:

 

 

DateTime.Date(
    Date.AddDays( 
    Date.StartOfMonth( DateTime.LocalNow())
    ,-1))

 

 

 

You may find this link on how to use the function useful

https://docs.microsoft.com/en-us/powerquery-m/datetime-date

 

Best,

Eric

Ashish_Mathur
Super User
Super User

Hi,

This should help.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

after this advanced editing, right click the Date/Time columns to change type to Date! No errors 😀

v-qiuyu-msft
Community Support
Community Support

Hi @NirH_at_BITeam

 

You can go to Query Editor, click on the left icon of the column name, then select the Date to change DateTime type to Date type. The corresponding M query uses the Table.TransformColumnTypes() function. 

 

q1.PNG

 

 

Best Regards,
Qiuyun Yu 

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.