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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Day number of year

Trying to find the syntax for to return a numer out of 1-365 for what number of day in year it is vs just knowing the number in the month  

1 ACCEPTED SOLUTION

@Anonymous

 

You can also add a calcualted column in DAX.

 

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

Capture.PNG

View solution in original post

13 REPLIES 13
powertrader
New Member

Not seeing Date.Dayofyear coming up in any function within BI

Just use DAX

Why should we have to creeate a DAX function for something so simple as Day of the Year?

God I hate PBI more and more every day I use it.

jure_rak
Helper I
Helper I

Just an additional application: I need to create a day number for a harvest year from 1-Jul till 30-Jun. Using solution from this query I did the following:

 

HarvYearDay = IF( 
            MONTH( DateTable[Date] ) > 6, 
                DATEDIFF( DATE ( YEAR ( DateTable[Date] ), 7, 1 ), DateTable[Date], DAY ) + 1, 
                DATEDIFF( DATE ( YEAR ( DateTable[Date] ), 1, 1 ), DateTable[Date], DAY ) + 185
            )

 

This is just to share if someone needs to do the same.

KGrice
Memorable Member
Memorable Member

Check out the Date.DayOfYear formula. You would use this in the query editor to add a new column, either as a custom column using the formula, or the simple way through the UI: select your date column, then to go the Add Column tab in the ribbon and use the drop-down on Date to select Day > Day of Year.

@Anonymous

 

You can also add a calcualted column in DAX.

 

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

Capture.PNG

OMG - does PBI really suck this much that this is what MS suggests? Makes me miss the overly complicated SSRS.

 

And the probably correct way for the day of the year is 


Stupid Column Name = FORMAT([CallDate], "y")

 

OMG - is this really the way to calculate the day of the year? I hate power bi more and more every day.

Ha 🙂 I just had the EXACT same reaction. Really?!?? If you can do it in M Query, why not replicate in Dax?
But then, you can't numerically set column widths, either. Or easily replicate a filter set up for HALF the visuals on a page (so NOT page level, NOT report level). Or dynamically name measures, or format all columns at once, or....
I miss VBA. But I also miss Fortran and Pascal, so guess I am a dinasour... 🐱🐉

If you have a date table that has all the dates between 2 periods you can also use this method 

 

Calendar_Day_Of_The_Year = RANKX(FILTER(Dim_Date, Dim_Date[Calendar_Year] = EARLIER(Dim_Date[Calendar_Year])),Dim_Date[Date], , ASC, Dense)
 
the example shows my date table as Dim_date. this then ranks the days of the year using the date. this can be used for any period ie, day of quarter / day of fiscal year, as long as you have a column which states the period.
 
P_d2023_0-1680893556368.png

 

Hello,

 

I was able to use this solution to calculate the day number of the year. I was wondering if anybody had any ideas on how to calculate this for a fiscal year and account for the leap year?

 

My organizations fiscal year starts in October. I was able to use the DAX formula below to calculate the fiscal day number of the year but when leap years occur the formula does not calculate correctly. 

 

FiscalDayoftheYear = IF('Date'[DayofhtheYear]>273,'Date'[DayofhtheYear]-273,'Date'[DayofhtheYear]+92)

 

If anyone has any ideas that would be great! Thanks!

Anonymous
Not applicable

Did you ever digure it out? Got the same problem.

I have to calculate Day number of Quarter and Day number of Month help me please.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.