cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
marijane12 Regular Visitor
Regular Visitor

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

Accepted Solutions
Super User
Super User

Re: Fail to convert integers to month or year

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.

1 REPLY 1
Super User
Super User

Re: Fail to convert integers to month or year

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
Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Power BI Helps Homeless and Trouble Youth

Power BI Helps Homeless and Trouble Youth

We spoke with Power BI Super User, Greg Deckler, about his charity work

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Top Kudoed Authors
Users Online
Currently online: 433 members 4,415 guests
Please welcome our newest community members: