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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
Anonymous
Not applicable

Help with Date Calculated column

Hi all,

 

I am trying to create a calculated column where in if date is equal to "2019/11/24" then print Static otherwise the date value. I am using the below two logic but keep getting an error - "Expression that yield variant date-type cannot be used to define calculated column"

The date column is of type "Date/time" with format "dd-mm-yyyy hh:min:sec(G)" - Please help

 

Column = If(Table1[date] = Date(2019,11,24),"Static",Table1[date])

Column = If(Table[date] = DateValue("2019-11-24"),"Static",Table1[date])

 

Thanks,

Vikash 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

Try like

Column = If(Table1[date] = Date(2019,11,24),"Static",format(Table1[date],"dd-mm-yyyy hh:mi:ss"))

 

for full set of options refer

https://docs.microsoft.com/en-us/dax/custom-date-and-time-formats-for-the-format-function

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

5 REPLIES 5
v-lionel-msft
Community Support
Community Support

Hi @Anonymous ,

 

This error is reported because your calculated column returned two types of data: text & date.

So, you can refer to @amitchandak 's answer.

x1.PNG

 

Best regards,
Lionel Chen

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

amitchandak
Super User
Super User

Try like

Column = If(Table1[date] = Date(2019,11,24),"Static",format(Table1[date],"dd-mm-yyyy hh:mi:ss"))

 

for full set of options refer

https://docs.microsoft.com/en-us/dax/custom-date-and-time-formats-for-the-format-function

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thanks very much @amitchandak , It worked. I now understand that the return type has to be same datatype.

@Anonymous , Appreciate if you can mark the solution. It will help others to find the solution easily

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
edhans
Super User
Super User

Go into Power Query (Transform Data button on home ribbon) and verify that is truly a date column. I bet it shows ABC/123 as the column data type. Click that and change it to date, or date/time.

 

Just because visually it looks like a date doesn't mean Power BI will see it as a date. It must actually be the Date data type.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors