cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Syndicate_Admin
Administrator
Administrator

Fiscal Year / Calendar Year

Hi, 

 

I need help creating a new column in Power Query where I create a Calendar Year. 

 

Our fiscal year begins in July. 

 

 

Id like a column named "Calendar Year"

Thanks!

4 REPLIES 4
Syndicate_Admin
Administrator
Administrator

You can create a custom column with this expression.

 

= if Date.Month([Merged])>6 then Date.Year([Merged]) + 1 else Date.Year([Merged])

 

Pat

Syndicate_Admin
Administrator
Administrator

Hi @amandabus21 ,

 

Create a blank query, go to the advanced editor, delete everything in the editor, and then paste the code below:

let
    startDate = #date(2020, 1, 1),                                      //start date. update the date if you need it
    endDate = Date.From(DateTime.LocalNow()),                           //Today date
    numMonths = Duration.Days(endDate - startDate),                     //get number of months
    dateList = List.Dates(startDate, numMonths, #duration(1,0,0,0)),    //generate a list of dates
    generateCalendar = List.Transform(
                            dateList, 
                            each 
                            {                                           
                                    _,                                  //date
                                    Date.Day(_),                        //get day
                                    Date.Month(_),                      //get month
                                    Date.Year(_),                       //get year
                                    Date.DayOfWeekName(_),              //get day of week name
                                    Date.MonthName(_),                  //get month name    
                                    (                                   //get financial period
                                        if Date.Month(_)-6 < 1 
                                        then Date.Month(_)+6 
                                        else Date.Month(_)-6
                                    ), 
                                    (                                   //get financial year
                                        if _ > #date(Date.Year(_),6,30) 
                                        then "FY"&Date.ToText(_,"yyyy")&"-"&Date.ToText(Date.AddYears(_,1),"yy") 
                                        else "FY"&Date.ToText(Date.AddYears(_,-1),"yyyy")&"-"&Date.ToText(_,"yy")
                                    )
                                }
                        ),
    output = Table.FromRows(
                    generateCalendar, 
                    {                                                   //column name: same order as above
                        "Date",                                         
                        "Day", 
                        "Month", 
                        "Year", 
                        "Day Of Week", 
                        "Month Name", 
                        "Financial Period", 
                        "Financial Year"
                    }
                )
in
    output

 

Regards

KT

Hi, @ppm1 

 

I ran into an issue with this.

 

 

The calendar year should be "2022" not 2024. 

 

Thank you for your help!

 

@ppm1 was able to fix with "-1" instead of "+1" thank you!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (2,434)