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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

Fiscal Date Table Doesn't respect quarters

Hello, I created a parameter query for a fiscal date table. My fiscal year starts in May but the date table doesn't respect it, it puts my quarters into a calendar year. This is the query I use to create the table. let fnDateTable = (StartDate as date, EndDate as date, FYStartMonth as number) as table => let EndDate = Date.AddYears(Date.EndOfYear(Date.From(DateTime.FixedLocalNow())),1), DayCount = Duration.Days(Duration.From(EndDate - StartDate)), DayCountAdd = DayCount + 1, Source = List.Dates(StartDate,DayCountAdd,#duration(1,0,0,0)), TableFromList = Table.FromList(Source, Splitter.SplitByNothing()), ChangedType = Table.TransformColumnTypes(TableFromList,{{"Column1", type date}}), RenamedColumns = Table.RenameColumns(ChangedType,{{"Column1", "Date"}}), InsertYear = Table.AddColumn(RenamedColumns, "Year", each Date.Year([Date]),type text), InsertYearNumber = Table.AddColumn(RenamedColumns, "YearNumber", each Date.Year([Date])), InsertQuarter = Table.AddColumn(InsertYear, "QuarterOfYear", each Date.QuarterOfYear([Date])), InsertMonth = Table.AddColumn(InsertQuarter, "MonthOfYear", each Date.Month([Date]), type text), InsertDay = Table.AddColumn(InsertMonth, "DayOfMonth", each Date.Day([Date])), InsertDayInt = Table.AddColumn(InsertDay, "DateInt", each [Year] * 10000 + [MonthOfYear] * 100 + [DayOfMonth]), InsertMonthName = Table.AddColumn(InsertDayInt, "MonthName", each Date.ToText([Date], "MMMM"), type text), InsertCalendarMonth = Table.AddColumn(InsertMonthName, "MonthInCalendar", each (try(Text.Range([MonthName],0,3)) otherwise [MonthName]) & " " & Number.ToText([Year])), InsertCalendarQtr = Table.AddColumn(InsertCalendarMonth, "QuarterInCalendar", each "Q" & Number.ToText([QuarterOfYear]) & " " & Number.ToText([Year])), InsertDayWeek = Table.AddColumn(InsertCalendarQtr, "DayInWeek", each Date.DayOfWeek([Date])), InsertDayName = Table.AddColumn(InsertDayWeek, "DayOfWeekName", each Date.ToText([Date], "dddd"), type text), InsertWeekEnding = Table.AddColumn(InsertDayName, "WeekEnding", each Date.EndOfWeek([Date]), type date), InsertWeekNumber= Table.AddColumn(InsertWeekEnding, "Week Number", each Date.WeekOfYear([Date])), InsertMonthnYear = Table.AddColumn(InsertWeekNumber,"MonthnYear", each [Year] * 10000 + [MonthOfYear] * 100), InsertQuarternYear = Table.AddColumn(InsertMonthnYear,"QuarternYear", each [Year] * 10000 + [QuarterOfYear] * 100), ChangedType1 = Table.TransformColumnTypes(InsertQuarternYear,{{"QuarternYear", Int64.Type},{"Week Number", Int64.Type},{"Year", type text},{"MonthnYear", Int64.Type}, {"DateInt", Int64.Type}, {"DayOfMonth", Int64.Type}, {"MonthOfYear", Int64.Type}, {"QuarterOfYear", Int64.Type}, {"MonthInCalendar", type text}, {"QuarterInCalendar", type text}, {"DayInWeek", Int64.Type}}), InsertShortYear = Table.AddColumn(ChangedType1, "ShortYear", each Text.End(Text.From([Year]), 2), type text), AddFY = Table.AddColumn(InsertShortYear, "FY", each "FY"&(if [MonthOfYear]>=FYStartMonth then Text.From(Number.From([ShortYear])+1) else [ShortYear])) in AddFY in fnDateTable
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

The code above is unformatted, not able to get that. But this how we calculated a qtr based on FY

 

Quarter = 
  SWITCH(
    TRUE(),
    'Date'[date] >= DATE(year('Date'[date])-1,9,27) && 'Date'[date] <= DATE(year('Date'[date])-1,12,31),"Q4",
    'Date'[date] >= DATE(year('Date'[date]),1,1) && 'Date'[date] <= DATE(year('Date'[date]),3,4),"Q1",
    'Date'[date] >= DATE(year('Date'[date]),3,4) && 'Date'[date] <= DATE(year('Date'[date]),9,30),"Q2",
    "Q3"
)

 

Need to change based on your requirements.

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks.

My Recent Blog - https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

The code above is unformatted, not able to get that. But this how we calculated a qtr based on FY

 

Quarter = 
  SWITCH(
    TRUE(),
    'Date'[date] >= DATE(year('Date'[date])-1,9,27) && 'Date'[date] <= DATE(year('Date'[date])-1,12,31),"Q4",
    'Date'[date] >= DATE(year('Date'[date]),1,1) && 'Date'[date] <= DATE(year('Date'[date]),3,4),"Q1",
    'Date'[date] >= DATE(year('Date'[date]),3,4) && 'Date'[date] <= DATE(year('Date'[date]),9,30),"Q2",
    "Q3"
)

 

Need to change based on your requirements.

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks.

My Recent Blog - https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

Anonymous
Not applicable

Thank you!  Works perfectly.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.