Forum Discussion

pmstahl's avatar
pmstahl
Frequent Visitor
6 years ago
Solved

Custom Fiscal Calendar Look Up

I am looking for a solution that will generate a calendar look up table for my company's fiscal calendar.    Our fiscal weeks run from Saturday - Friday.  The fiscal year begins the Saturday after...
  • edhans's avatar
    edhans
    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