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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Create a new column with DAX

Hello!

i have a column like follows: 

6/12/2022 2:50:00 PM
6/12/2022 3:42:10 PM

6/12/2022 3:50:17 PM

6/13/2022 1:19:47 AM

6/13/2022 4:12:58 AM
...

I want to create a column which only has the date included: 

6/12/2022
6/12/2022

6/12/2022 

6/13/2022

6/13/2022

 

Which DAX Expression do I have to use? 

Thanks! 🙂 

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @Anonymous ,

 

The solution will depend on the data type of the column you're trying to create a calculated column from. If it is a date, you simpley use INT ( Table[Column] ) and format the new column as a date - INT for integer as a datetime is actually a whole number for the date and decimal for the time. Otherswise, if it is a text, the formula will be very simIlar as in Excel.

Date only =
VAR __SPACE =
    FIND ( " ", 'Table'[Date and time] ) - 1 //find the position of space from the left then -1  to get the position before it
RETURN
    VALUE ( LEFT ( 'Table'[Date and time], __SPACE ) )
//VALUE is for converting the text date to actual date









Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

6 REPLIES 6
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

Is your problem solved?? If so, Would you mind accept the helpful replies as solutions? Then we are able to close the thread. More people who have the same requirement will find the solution quickly and benefit here. Thank you.

Best Regards,
Community Support Team _ kalyj

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

danextian
Super User
Super User

Hi @Anonymous ,

 

The solution will depend on the data type of the column you're trying to create a calculated column from. If it is a date, you simpley use INT ( Table[Column] ) and format the new column as a date - INT for integer as a datetime is actually a whole number for the date and decimal for the time. Otherswise, if it is a text, the formula will be very simIlar as in Excel.

Date only =
VAR __SPACE =
    FIND ( " ", 'Table'[Date and time] ) - 1 //find the position of space from the left then -1  to get the position before it
RETURN
    VALUE ( LEFT ( 'Table'[Date and time], __SPACE ) )
//VALUE is for converting the text date to actual date









Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Anonymous
Not applicable

Exactly what I looked for. 
But i get an error saying "An argument of function "FIND" hast the wrong data type or has an invalid value". 
The used data type is "date/time". @danextian 

FIND is a text function so if a data type other than text is used it will return an error. If you need to extract the date portion of a datetime, you can use INT() or DATE(YEAR(Table[DateTime]), MONTH (Table[DateTime]), DAY(Table[DateTime]) )










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

As mentioned, the solution will depend on the data type. Is it a text or a datetime?










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Greg_Deckler
Super User
Super User

@Anonymous Well, you could do this:

New Column = DATE(YEAR([Date]),MONTH([Date]),DAY([Date]))


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.