Using a Day of Year for a Fiscal Year

cmgish

New Member
Joined
Feb 15, 2021
Messages
8
Office Version
  1. 365
Platform
  1. Windows
My organization operates on a fiscal year (June - May), and I need to create a custom column in Power Query that will give me the Day of the Year with June 1st being the first day of the year. I should say that I don't fully understand M code. I am learning a little, but am still a novice at this. Here is a screenshot of my Calendar query:
1677777668882.png

I appreciate any help I can get. I really want to learn how to do more custom work in Power Query, so if anyone also has some site suggestions on the best way to learn M code, that would also be appreciated. Thank you!

Chris
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi,
For the fiscal "day" formula, you could test
Excel Formula:
=TODAY()-DATE(IF(MONTH(TODAY())<6,YEAR(TODAY())-1,YEAR(TODAY())),6,1)
 
Upvote 0
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    tbl = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    Result = Table.AddColumn(tbl, "Day of Fiscal Year", each Date.DayOfYear([Date])- Date.DayOfYear(#date(Date.Year([Date]),5,31)))
in
    Result

Book2
ABCDE
1DateDateDay of Fiscal Year
26/1/20236/1/20231
36/2/20236/2/20232
46/3/20236/3/20233
56/4/20236/4/20234
66/5/20236/5/20235
76/6/20236/6/20236
86/7/20236/7/20237
9
Sheet2
 
Upvote 0
This code comes from this video.
Power Query:
let
   //courtesy of AccessAnalytic.com.au


    Today = Date.From(DateTime.LocalNow() ),  

   // Change start date to begining of year
    StartDate= #date(2022, 1, 1),        
    
   //see advanced editor for note on alternative hardcoding EndDate method
    YearsInFuture = 0,
    EndDate = Date.EndOfYear(Date.AddYears(Today,YearsInFuture )),

    // Or comment out the 2 lines above replace with manual End Date below.. use end of year   
    //EndDate = #date(2021, 12, 31), 
    PointlessStepAddedToBreakCommentInAdvancedEditor = "",


    //set this as the last month number of your fiscal year : June = 6, July =7 etc
    MonthNumberForEndFinancialYear = 6,

   // Change to Day.Sunday or Day.Tuesday etc to impact the sort order number so you can then display your days in your visuals in the preferred way
    FirstDayOfWeek = Day.Monday,   



    DateList = {Number.From(StartDate)..Number.From(EndDate)},
    

    ConvertedDateListToTable = Table.FromList(DateList, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    RenamedDate = Table.RenameColumns(ConvertedDateListToTable,{{"Column1", "Date"}}),
    ChangedType1 = Table.TransformColumnTypes(RenamedDate,{{"Date", type date}}),
    InsertedYear = Table.AddColumn(ChangedType1, "Year", each Date.Year([Date]), type number),
    InsertedMonthNumber = Table.AddColumn(InsertedYear, "Month Number", each Date.Month([Date]), type number),
    InsertedShortMonthName = Table.AddColumn(InsertedMonthNumber, "Month", each Text.Start(Date.MonthName([Date]),3), type text),
    InsertedShortDayName = Table.AddColumn(InsertedShortMonthName, "Day", each Text.Start( Date.DayOfWeekName([Date]),3), type text),
    InsertedDayOfWeekNumberMon0 = Table.AddColumn(InsertedShortDayName, "Day of Week", each Date.DayOfWeek([Date],FirstDayOfWeek), Int64.Type),
    InsertedQuarterNumber = Table.AddColumn(InsertedDayOfWeekNumberMon0, "QuarterNumber", each Date.QuarterOfYear([Date]),Int64.Type),
    ChangedType2 = Table.TransformColumnTypes(InsertedQuarterNumber,{{"QuarterNumber", type text}, {"Year", type text}}),
    AddedQuarterNumberQx = Table.AddColumn(ChangedType2, "Quarter", each "Q"&[QuarterNumber], type text),
    RemovedQuarterDigit = Table.RemoveColumns(AddedQuarterNumberQx,{"QuarterNumber"}),
    AddedYYQQ = Table.AddColumn(RemovedQuarterDigit, "YY-QQ", each Text.End( [Year],2) & "-"& [Quarter], type text),
    ChangedType4 = Table.TransformColumnTypes(AddedYYQQ,{{"YY-QQ", type text}, {"Year", Int64.Type}}),
    #"▶ DatesSinceTodayFields" = ChangedType4,
    DateToday = Today,
    DaysAgo = Table.AddColumn(#"▶ DatesSinceTodayFields", "Days Since Today", each Duration.Days([Date] -  DateToday), Int32.Type),
    MonthsAgo = Table.AddColumn(DaysAgo, "Months Since Today", each ([Year] * 12 + [Month Number]) - (Date.Year(DateToday ) * 12 + Date.Month(DateToday )), Int32.Type),
    YearsAgo = Table.AddColumn(MonthsAgo, "Years Since Today", each [Year] - Date.Year(DateToday ), Int32.Type),
    #"◀ DatesSinceToday" = YearsAgo,
    #"▶FinancialYearCalcs" = #"◀ DatesSinceToday",
    FYMonthNumber = Table.AddColumn(#"▶FinancialYearCalcs", "Financial Month Number", each if [Month Number] > MonthNumberForEndFinancialYear  then [Month Number]-MonthNumberForEndFinancialYear  else 12-MonthNumberForEndFinancialYear+[Month Number]),
    ChangedType5 = Table.TransformColumnTypes(FYMonthNumber,{{"Financial Month Number", Int64.Type}}),
    FinancialYearEnd = Table.AddColumn(ChangedType5, "Financial Year End", each if [Financial Month Number] <=12-MonthNumberForEndFinancialYear  then [Year]+1 else [Year]),
    FiancialYearStart = Table.AddColumn(FinancialYearEnd, "Financial Year Start", each [Financial Year End] - 1, type number),
    ChangedType6 = Table.TransformColumnTypes(FiancialYearStart,{{"Financial Year End", type text}, {"Financial Year Start", type text}}),
    AddedFinancialYearRange = Table.AddColumn(ChangedType6, "Financial Year", each Text.End( [Financial Year Start],2) & "-" & Text.End([Financial Year End],2)),
    RemovedColumns1 = Table.RemoveColumns(AddedFinancialYearRange,{"Financial Year End", "Financial Year Start"}),
    // To work out Financial Quarter
    DivideFinancialMonthBy3 = Table.AddColumn(RemovedColumns1, "Financial Qtr Number", each [Financial Month Number] / 3, type number),
    RoundedUpToGetQuarter = Table.TransformColumns(DivideFinancialMonthBy3,{{"Financial Qtr Number", Number.RoundUp, Int64.Type}}),
    AddedFinancialQuarter = Table.AddColumn(RoundedUpToGetQuarter, "Financial Quarter", each "FQ-"&Text.From([Financial Qtr Number])),
    RemovedFyqHelper = Table.RemoveColumns(AddedFinancialQuarter,{"Financial Qtr Number"}),
    ChangedType7 = Table.TransformColumnTypes(RemovedFyqHelper,{{"Financial Quarter", type text}, {"Financial Year", type text}}),
    #"◀ FinancialYearCalcs" = ChangedType7,
    RenamedSortColumns = Table.RenameColumns(#"◀ FinancialYearCalcs",{{"Month Number", "Month Number for sort"}, {"Financial Month Number", "Financial Month Number for sort"}, {"Day of Week", "Day of Week for sort"}})
in
    RenamedSortColumns
It is huge, but by changing a few items in the query, you're set with a Calendar Table, especially needed for all date calculations, especially in Power Query and DAX. Here's a small sample of the results:
Book1
ABCDEFGHIJKLMN
1DateYearMonth Number for sortMonthDayDay of Week for sortQuarterYY-QQDays Since TodayMonths Since TodayYears Since TodayFinancial Month Number for sortFinancial YearFinancial Quarter
201/01/202220221JanSat5Q122-Q1-429-14-1721-22FQ-3
301/02/202220221JanSun6Q122-Q1-428-14-1721-22FQ-3
401/03/202220221JanMon0Q122-Q1-427-14-1721-22FQ-3
501/04/202220221JanTue1Q122-Q1-426-14-1721-22FQ-3
Sheet1

It's a bit more than requested, but a great tool to have!
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top