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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
waleed111
Helper V
Helper V

YEAR function

YEAR function generate wrong values:

Year A = Year('All Manufacturings (4)'[Added Time])
it gave me 1905 for all values, what is the problem?
 
1 ACCEPTED SOLUTION

Hello @waleed111 ,

Based on the sample data, how did you create this [Time Added] column? Basically the Year() function will return the corresponding year of the column value and works well in my environment if the column is using formula or quote directly.

y1.pngy2.png

Maybe you can also try using .year to check:

Column 3 = 'Calendar'[Date]. [Year]

In addition, if you use the format() function to get the year value, it will be displayed as the default text type and can only be converted to the sunch number type as integer, decimal number, and so on, the date type is not allowed.

Like this:

Column 4 = CONVERT(FORMAT('Calendar'[Date],"YYYY"),DOUBLE)
Column 4 = CONVERT(FORMAT('Calendar'[Date],"YYYY"),INTEGER)

Best Looks,
Yingjie Li

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

View solution in original post

7 REPLIES 7
amitchandak
Super User
Super User

@waleed111 , Was it the date time column having only time added with some days. or was it the duration column.  Power does add date to the time column. because of that, you might get that.

 

Can you share sample data and sample output in table format?

 

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

year.PNG

Hello @waleed111 ,

Based on the sample data, how did you create this [Time Added] column? Basically the Year() function will return the corresponding year of the column value and works well in my environment if the column is using formula or quote directly.

y1.pngy2.png

Maybe you can also try using .year to check:

Column 3 = 'Calendar'[Date]. [Year]

In addition, if you use the format() function to get the year value, it will be displayed as the default text type and can only be converted to the sunch number type as integer, decimal number, and so on, the date type is not allowed.

Like this:

Column 4 = CONVERT(FORMAT('Calendar'[Date],"YYYY"),DOUBLE)
Column 4 = CONVERT(FORMAT('Calendar'[Date],"YYYY"),INTEGER)

Best Looks,
Yingjie Li

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

@waleed111 

It must be Data Type issue in the Add Column . Have you checked the DAta type OR

Try using Format([Date],"YYYY") and let me know whethe you are able to get the Year




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


now FORMAT function work but it show me this error:

Cannot convert value '2020' of type Text to type Date.

@waleed111 

Year can be Text . Any  Specific purpose you want that to be as number.

For Example if you want to use Year in Filter Context , then you can use "2020" to achieve the target

Hope this clarifies. If you have find this as solution please mark this a ssolution and share your Kudoes

Vijay Perepa




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


VijayP
Super User
Super User

@waleed111 

Year Function only can handle Dates, you are giving Hours:Minutes as an argument




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.