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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Custom Calendar/Date according to Accounting Period

Hi,

I'm trying to format my calendar according to my company's accounting period.

Example, from 26/11/2020 -25/12/2020, this will considered as December 2020.
From 26/12/2020 - 25/1/2021, this will be considered as January 2021.

I've tried to think of a way but couldn't get it right. Anyone have experience with this and can share with me?

Thanks a lot.

1 ACCEPTED SOLUTION
AllisonKennedy
Super User
Super User

@Anonymous 

 

Please see if this Power Query code will work for you, adapted from this site; https://excelwithallison.blogspot.com/2020/04/dimdate-what-why-and-how.html 

 

 

let
startDate = #date(2019, 1, 1),
// Edit the number in this step to change the number of months after today for the last day of the Calendar table.
endDate = Date.AddMonths(Date.From(DateTime.LocalNow()),3),
Dates = List.Dates(startDate, Duration.Days(endDate - startDate), #duration (1,0,0,0)),
#"Converted to Table" = Table.FromList(Dates, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Date"}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Date", type date}}),
#"Inserted DateKey" = Table.AddColumn(#"Changed Type", "DateKey", each Date.ToText([Date],"yyyyMMdd"), type text),
#"Inserted Year" = Table.AddColumn(#"Inserted DateKey", "Year", each Date.Year([Date]), Int64.Type),
#"Inserted Quarter" = Table.AddColumn(#"Inserted Year", "Quarter", each Date.QuarterOfYear([Date]), Int64.Type),
#"Inserted FY Quarters" = Table.AddColumn(#"Inserted Quarter", "FY Quarter", each if [Quarter] = 1 then "4" else if [Quarter] = 2 then "1" else if [Quarter] = 3 then "2" else "3", type text),
#"Inserted Month Name" = Table.AddColumn(#"Inserted FY Quarters", "Month name", each Date.MonthName([Date]), type text),
#"Inserted Month" = Table.AddColumn(#"Inserted Month Name", "Month number", each Date.Month([Date]), Int64.Type),
#"Inserted Day of Month" = Table.AddColumn(#"Inserted Month", "Day of month", each Date.Day([Date]), Int64.Type),
#"Inserted Day of Year" = Table.AddColumn(#"Inserted Day of Month", "Day of Year", each Date.DayOfYear([Date]), Int64.Type),
#"Inserted Day of Week" = Table.AddColumn(#"Inserted Day of Year", "Day of Week", each Date.DayOfWeek([Date]), Int64.Type),
#"Inserted Day Name" = Table.AddColumn(#"Inserted Day of Week", "Day name", each Date.DayOfWeekName([Date]), type text),
// In Week functions
// 0 represents Sunday start
// 1 represents Monday start
// 2 represents Tuesday start
#"Inserted Week of Year" = Table.AddColumn(#"Inserted Day Name", "Week of Year", each Date.WeekOfYear([Date],1), Int64.Type),
#"Inserted Week of Month" = Table.AddColumn(#"Inserted Week of Year", "Week of Month", each Date.WeekOfMonth([Date],1), Int64.Type),
#"Inserted FY start" = Table.AddColumn(#"Inserted Week of Month", "FY starts", each [Year] + (if [Month number] > 3 then 0 else -1), type number),
#"Inserted FY" = Table.AddColumn(#"Inserted FY start", "FY", each Text.From([FY starts]) & "/" & Text.From([FY starts] + 1), type text),
#"Inserted FY and Quarter" = Table.AddColumn(#"Inserted FY", "FY and Quarter", each Text.Combine({Text.From([FY starts], "en-NZ"), [FY Quarter]}, " Q"), type text),
#"Inserted Merged Column" = Table.AddColumn(#"Inserted FY and Quarter", "FY and Quarter Sort", each Text.Combine({Text.From([FY starts]), [FY Quarter]}, ""), type text),
#"Inserted Custom Month Number" = Table.AddColumn(#"Inserted Merged Column", "Company Custom Month Number", each if [Day of month] <= 25 then [Month number] else ( if [Month number]<12 then [Month number] +1 else 1)),
#"Inserted Custom Year" = Table.AddColumn(#"Inserted Custom Month Number", "Company Custom Year", each if [Day of month] >= 26 and [Month number] =12 then [Year] +1 else [Year]),
#"Inserted Custom Month Name" = Table.AddColumn(#"Inserted Custom Year", "Company Custom Month Name", each if [Company Custom Month Number] = 1 then "January" else if [Company Custom Month Number] = 2 then "February"
else if [Company Custom Month Number] = 3 then "March" else if [Company Custom Month Number] = 4 then "April" else if [Company Custom Month Number] = 5 then "May" else if [Company Custom Month Number] = 6 then "June" else if [Company Custom Month Number] = 7 then "July" else if [Company Custom Month Number] = 8 then "August" else if [Company Custom Month Number] = 9 then "September" else if [Company Custom Month Number] = 10 then "October" else if [Company Custom Month Number] = 11 then "November" else "December"),
#"Inserted Custom Month Year" = Table.AddColumn(#"Inserted Custom Month Name", "Company Custom Month Year", each Text.Combine({[Company Custom Month Name], Text.From([Company Custom Year], "en-US")}, " "), type text)
in
#"Inserted Custom Month Year"


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

5 REPLIES 5
StefanoGrimaldi
Resident Rockstar
Resident Rockstar

here you go, this will set the between condition you looking forby specific intervals and assign the period, if isnt setted the condition wil tell no parameterss to define accountable period

StefanoGrimaldi_0-1609117947731.png

 

create a new date table with the range of the calendar or autocalendar and set up this column to define the accountable period by date. 

 





Did I answer your question? Mark my post as a solution! / Did it help? Give some Kudos!

Proud to be a Super User!




AllisonKennedy
Super User
Super User

@Anonymous 

 

Please see if this Power Query code will work for you, adapted from this site; https://excelwithallison.blogspot.com/2020/04/dimdate-what-why-and-how.html 

 

 

let
startDate = #date(2019, 1, 1),
// Edit the number in this step to change the number of months after today for the last day of the Calendar table.
endDate = Date.AddMonths(Date.From(DateTime.LocalNow()),3),
Dates = List.Dates(startDate, Duration.Days(endDate - startDate), #duration (1,0,0,0)),
#"Converted to Table" = Table.FromList(Dates, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Date"}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Date", type date}}),
#"Inserted DateKey" = Table.AddColumn(#"Changed Type", "DateKey", each Date.ToText([Date],"yyyyMMdd"), type text),
#"Inserted Year" = Table.AddColumn(#"Inserted DateKey", "Year", each Date.Year([Date]), Int64.Type),
#"Inserted Quarter" = Table.AddColumn(#"Inserted Year", "Quarter", each Date.QuarterOfYear([Date]), Int64.Type),
#"Inserted FY Quarters" = Table.AddColumn(#"Inserted Quarter", "FY Quarter", each if [Quarter] = 1 then "4" else if [Quarter] = 2 then "1" else if [Quarter] = 3 then "2" else "3", type text),
#"Inserted Month Name" = Table.AddColumn(#"Inserted FY Quarters", "Month name", each Date.MonthName([Date]), type text),
#"Inserted Month" = Table.AddColumn(#"Inserted Month Name", "Month number", each Date.Month([Date]), Int64.Type),
#"Inserted Day of Month" = Table.AddColumn(#"Inserted Month", "Day of month", each Date.Day([Date]), Int64.Type),
#"Inserted Day of Year" = Table.AddColumn(#"Inserted Day of Month", "Day of Year", each Date.DayOfYear([Date]), Int64.Type),
#"Inserted Day of Week" = Table.AddColumn(#"Inserted Day of Year", "Day of Week", each Date.DayOfWeek([Date]), Int64.Type),
#"Inserted Day Name" = Table.AddColumn(#"Inserted Day of Week", "Day name", each Date.DayOfWeekName([Date]), type text),
// In Week functions
// 0 represents Sunday start
// 1 represents Monday start
// 2 represents Tuesday start
#"Inserted Week of Year" = Table.AddColumn(#"Inserted Day Name", "Week of Year", each Date.WeekOfYear([Date],1), Int64.Type),
#"Inserted Week of Month" = Table.AddColumn(#"Inserted Week of Year", "Week of Month", each Date.WeekOfMonth([Date],1), Int64.Type),
#"Inserted FY start" = Table.AddColumn(#"Inserted Week of Month", "FY starts", each [Year] + (if [Month number] > 3 then 0 else -1), type number),
#"Inserted FY" = Table.AddColumn(#"Inserted FY start", "FY", each Text.From([FY starts]) & "/" & Text.From([FY starts] + 1), type text),
#"Inserted FY and Quarter" = Table.AddColumn(#"Inserted FY", "FY and Quarter", each Text.Combine({Text.From([FY starts], "en-NZ"), [FY Quarter]}, " Q"), type text),
#"Inserted Merged Column" = Table.AddColumn(#"Inserted FY and Quarter", "FY and Quarter Sort", each Text.Combine({Text.From([FY starts]), [FY Quarter]}, ""), type text),
#"Inserted Custom Month Number" = Table.AddColumn(#"Inserted Merged Column", "Company Custom Month Number", each if [Day of month] <= 25 then [Month number] else ( if [Month number]<12 then [Month number] +1 else 1)),
#"Inserted Custom Year" = Table.AddColumn(#"Inserted Custom Month Number", "Company Custom Year", each if [Day of month] >= 26 and [Month number] =12 then [Year] +1 else [Year]),
#"Inserted Custom Month Name" = Table.AddColumn(#"Inserted Custom Year", "Company Custom Month Name", each if [Company Custom Month Number] = 1 then "January" else if [Company Custom Month Number] = 2 then "February"
else if [Company Custom Month Number] = 3 then "March" else if [Company Custom Month Number] = 4 then "April" else if [Company Custom Month Number] = 5 then "May" else if [Company Custom Month Number] = 6 then "June" else if [Company Custom Month Number] = 7 then "July" else if [Company Custom Month Number] = 8 then "August" else if [Company Custom Month Number] = 9 then "September" else if [Company Custom Month Number] = 10 then "October" else if [Company Custom Month Number] = 11 then "November" else "December"),
#"Inserted Custom Month Year" = Table.AddColumn(#"Inserted Custom Month Name", "Company Custom Month Year", each Text.Combine({[Company Custom Month Name], Text.From([Company Custom Year], "en-US")}, " "), type text)
in
#"Inserted Custom Month Year"


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Anonymous
Not applicable

Hi @AllisonKennedy ,

This works well. Thanks!

@Anonymous  You're welcome. Glad you found it useful. 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.