Forum Discussion
Custom Fiscal Calendar Look Up
- 6 years ago
How would you do that in Excel? In othe words, how do you count your weeks? We could implement just about any similar logic in Power Query to count the weeks.
EDIT: Had a thought: See if this code works. use this for the date table, or go get the PBIX file I linked to above. It has been updated.let Source = {Number.From(#date(2015,12,5))..Number.From(#date(2020,12,4))}, #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), {"Date"}, null, ExtraValues.Error), #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Date", type date}}), #"Appended Query" = Table.Combine({#"Changed Type", #"Fiscal Calendar Start Date"}), #"Sorted Rows" = Table.Sort(#"Appended Query",{{"Date", Order.Ascending}, {"Fiscal Year", Order.Descending}}), #"Filled Down" = Table.FillDown(#"Sorted Rows",{"Fiscal Year"}), #"Removed Duplicates" = Table.Distinct(#"Filled Down"), #"Inserted Year" = Table.AddColumn(#"Removed Duplicates", "Calendar Year", each Date.Year([Date]), Int64.Type), #"Inserted Day Name" = Table.AddColumn(#"Inserted Year", "Day Name", each Date.DayOfWeekName([Date]), type text), #"Added Fiscal Week" = Table.AddColumn( #"Inserted Day Name", "Fiscal Week", each let varCurrentDate = [Date], varFiscalYear = [Fiscal Year] in Number.RoundUp( Table.RowCount( Table.SelectRows(#"Inserted Day Name", each [Fiscal Year] = varFiscalYear and [Date] <= varCurrentDate) ) / 7 ) ) in #"Added Fiscal Week"1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
Thank you for taking the time to help me! It is greatly appreciated.
How would I create a column that would have the Fiscal Week Numbered 1-52 and in some years 53?
How would you do that in Excel? In othe words, how do you count your weeks? We could implement just about any similar logic in Power Query to count the weeks.
EDIT: Had a thought: See if this code works. use this for the date table, or go get the PBIX file I linked to above. It has been updated.
let
Source = {Number.From(#date(2015,12,5))..Number.From(#date(2020,12,4))},
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), {"Date"}, null, ExtraValues.Error),
#"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Date", type date}}),
#"Appended Query" = Table.Combine({#"Changed Type", #"Fiscal Calendar Start Date"}),
#"Sorted Rows" = Table.Sort(#"Appended Query",{{"Date", Order.Ascending}, {"Fiscal Year", Order.Descending}}),
#"Filled Down" = Table.FillDown(#"Sorted Rows",{"Fiscal Year"}),
#"Removed Duplicates" = Table.Distinct(#"Filled Down"),
#"Inserted Year" = Table.AddColumn(#"Removed Duplicates", "Calendar Year", each Date.Year([Date]), Int64.Type),
#"Inserted Day Name" = Table.AddColumn(#"Inserted Year", "Day Name", each Date.DayOfWeekName([Date]), type text),
#"Added Fiscal Week" =
Table.AddColumn(
#"Inserted Day Name",
"Fiscal Week",
each
let
varCurrentDate = [Date],
varFiscalYear = [Fiscal Year]
in
Number.RoundUp(
Table.RowCount(
Table.SelectRows(#"Inserted Day Name", each [Fiscal Year] = varFiscalYear and [Date] <= varCurrentDate)
) / 7
)
)
in
#"Added Fiscal Week"
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done