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

Fail to convert integers to month or year

Hi everyone
I try to use the formula year(ordPubAno); ordPub ano is formatted as whole number. 

The result of conversion for example for 2004 is 1905 but  it should be 2004.

I try to convert also a month(ordPubMês) odrPubMes is formatted as whole number and for example for 8 convert to 1 instead of 8.

Can you help?

1 ACCEPTED SOLUTION
Cmcmahan
Resident Rockstar
Resident Rockstar

The YEAR and MONTH functions expect a datetime object, not an integer.  When you pass an integer, DAX assumes that is the number of days that have passed since Dec 31, 1899.  So when you get the YEAR(2004), you're actually getting the year 2004 days after Dec 31, 1899.  Same with MONTH(8), which returns 1 since 8 days after Dec 31, 1899 it is January.

My question is why you're trying to convert a value that is a year into a year? You're expecting a result of 2004 when you input 2004 into the function. You already have the value you're expecting to come out of the function, so just use that.

View solution in original post

1 REPLY 1
Cmcmahan
Resident Rockstar
Resident Rockstar

The YEAR and MONTH functions expect a datetime object, not an integer.  When you pass an integer, DAX assumes that is the number of days that have passed since Dec 31, 1899.  So when you get the YEAR(2004), you're actually getting the year 2004 days after Dec 31, 1899.  Same with MONTH(8), which returns 1 since 8 days after Dec 31, 1899 it is January.

My question is why you're trying to convert a value that is a year into a year? You're expecting a result of 2004 when you input 2004 into the function. You already have the value you're expecting to come out of the function, so just use that.

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.