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
amandabus21
Helper V
Helper V

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. 

 

amandabus21_0-1666996902417.png

 

Id like a column named "Calendar Year"

Thanks!

1 ACCEPTED SOLUTION
ppm1
Solution Sage
Solution Sage

You can create a custom column with this expression.

 

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

 

Pat

Microsoft Employee

View solution in original post

5 REPLIES 5
KT_Bsmart2gethe
Impactful Individual
Impactful Individual

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

ppm1
Solution Sage
Solution Sage

You can create a custom column with this expression.

 

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

 

Pat

Microsoft Employee

How would I change this to be the first monday in april? 

Hi, @ppm1 

 

I ran into an issue with this.

 

amandabus21_0-1667242162624.png

 

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

Top Solution Authors
Top Kudoed Authors