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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
TechR21
Helper V
Helper V

Day number of year + year

Im using the following dax formula to count the day of the year.

 

DayNoOfYear =
DATEDIFF ( DATE ( YEAR ( 'Table'[Date] ), 1, 1 ), 'Table'[Date], DAY ) + 1

 

TechR21_0-1674556540506.png

 

Only problem is I have multiple years and I want to have unique value. 

 

How can i add a particular year to this? so that I get for example.

date: 2016-01-01

DayNoOfYear: 1-16

 

date: 2016-01-31

DayNoOfYear: 31-16

 

date: 2017-01-31

DayNoOfYear: 31-17

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @TechR21 

try to add a column like:

DayNoOfYear = 
VAR _days = DATEDIFF ( DATE ( YEAR ( [Date] ), 1, 1 ), [Date], DAY ) + 1
RETURN _days&"-"&FORMAT([Date], "YY")

FreemanZ_0-1674567965039.png

 

View solution in original post

4 REPLIES 4
FreemanZ
Super User
Super User

hi @TechR21 

try to add a column like:

DayNoOfYear = 
VAR _days = DATEDIFF ( DATE ( YEAR ( [Date] ), 1, 1 ), [Date], DAY ) + 1
RETURN _days&"-"&FORMAT([Date], "YY")

FreemanZ_0-1674567965039.png

 

perfect, thanks!

powerbi2srm
Resolver II
Resolver II

The simplest way is using "Add column from examples" in Power Query. Something like this:

Captura.PNG

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

Anonymous
Not applicable

Is there a reason you're not egetting the day number with the DAY() function?

 

You could make a calculated column like 

DAY('Calendar'[Date]) & " - " & RIGHT(YEAR('Calendar'[Date]),2)
 
RIGHT() just takes the last two characters of your year. Hope this helps

Helpful resources

Announcements
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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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