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
Anonymous
Not applicable

Error: Cannot convert value '0/01/' of type Text to type Date

I am new to PBI and I am trying to combine two columns into one.  I created a calculated column PERIOD which is based on the two original columns: YEAR and MONTH.  I am getting this error: Cannot convert value '0/01/' of type Text to type Date.  Any ideas?

 

 
 

PBI Error.png

 

 

 

 

2 ACCEPTED SOLUTIONS
AllisonKennedy
Super User
Super User

A couple of things:
1) The error is coming because you are getting to the 0 at the bottom of your IF statement - that means some of your months don't match. Have you done a Trim on this column in Power Query to remove any spaces?
2) You could use DATE() for this instead of DATEVALUE since your date parts are already separated. It means you won't have to use the & to concatenate and is a bit simpler to work with.
3) Use SWITCH instead of so many nested IF statements:
Period = DATE(Table[Year],
SWITCH( Table[Month]
, "Jan", 1
, "Feb", 2
, "Mar", 3
, "Apr", 4
, "May", 5
, "Jun", 6
...
),
1)


4) Since this is part of the data model and a calculated column, I would personally do this in Power QUERY, NOT in DAX.
https://radacad.com/m-or-dax-that-is-the-question/?ref=818
https://www.sqlbi.com/articles/comparing-dax-calculated-columns-with-power-query-computed-columns/

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

Try this calculated column formula

=1*("1/"&[Month]&"/"&[Year])

Format this column as Date.


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

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

Try this calculated column formula

=1*("1/"&[Month]&"/"&[Year])

Format this column as Date.


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

Thanks, Ashish.  This worked as well.  It took me a minute to realize I needed to add the column name in the formula "Period =1*("1/"&[Month]&"/"&[Year])".  Pretty slick

You are welcome.


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

A couple of things:
1) The error is coming because you are getting to the 0 at the bottom of your IF statement - that means some of your months don't match. Have you done a Trim on this column in Power Query to remove any spaces?
2) You could use DATE() for this instead of DATEVALUE since your date parts are already separated. It means you won't have to use the & to concatenate and is a bit simpler to work with.
3) Use SWITCH instead of so many nested IF statements:
Period = DATE(Table[Year],
SWITCH( Table[Month]
, "Jan", 1
, "Feb", 2
, "Mar", 3
, "Apr", 4
, "May", 5
, "Jun", 6
...
),
1)


4) Since this is part of the data model and a calculated column, I would personally do this in Power QUERY, NOT in DAX.
https://radacad.com/m-or-dax-that-is-the-question/?ref=818
https://www.sqlbi.com/articles/comparing-dax-calculated-columns-with-power-query-computed-columns/

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Anonymous
Not applicable

The DATE + SWITCH fix worked beautifully.  Thanks for the quick response and for sending a couple solutions.  I am sending you Virtual Kudos

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.