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
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.

ADPowerBI1
Responsive Resident
Responsive Resident

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
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.