Forum Discussion

Diksha's avatar
Diksha
Regular Visitor
1 year ago
Solved

Rolling 2 week, 4 week average

I have this table. What I want is rolling averages of 2 week, 4 week, 6 week and 8 week. Like in below table If I select date 15 from date master table. Then rolling 2 week is June 15 and June 8. So ...
  • SundarRaj's avatar
    SundarRaj
    1 year ago

    Hi Diksha, from the data mentioned by you, I have created a dummy dataset and followed your outcome / output. Here's the file, the image of the output and the code in text for your reference. Is this what you are looking for? Do let me know. Thanks

    File Link:

    https://docs.google.com/spreadsheets/d/1sNn__L9XwoRIZcKDXt6W10BtZdzNZpls/export?format=xlsx&ouid=104752674875039603034&rtpof=true&sd=true

    Here's the code:
    let
    Source = #table(
    {
    "Month",
    "Day",
    "Client Sub per Recruiter",
    "Sourcing Sub per Recruiter",
    "Average Sourcing Subs",
    "Average Client Subs",
    "Interviews",
    "Offers",
    "Temp Starts",
    "Contract Billable HC",
    "AWGP Run Rate"
    },
    {
    {"June", 8, 4.83, 6.31, 169, 130, 19.5, 6.5, 6.0, 104, 60411},
    {"June", 15, 4.45, 6.01, 165, 122, 17.5, 9.25, 7.5, 102, 55596},
    {"June", 22, 4.68, 6.26, 170, 128, 23.0, 10.38, 7.38, 95, 54320},
    {"June", 29, 4.95, 6.40, 174, 132, 21.0, 8.75, 6.75, 97, 56750},
    {"July", 6, 5.10, 6.55, 178, 134, 22.5, 9.00, 7.00, 99, 57980},
    {"July", 13, 4.88, 6.20, 171, 129, 20.0, 7.80, 6.50, 98, 55100},
    {"July", 20, 4.70, 6.00, 167, 126, 18.5, 6.90, 6.25, 96, 53850},
    {"July", 27, 4.92, 6.18, 173, 131, 19.8, 8.20, 6.90, 100, 56120}
    }
    ),
    #"Removed Columns" = Table.RemoveColumns(Source, {"Month", "Day"}),
    Unpivot = Table.Unpivot(
    #"Removed Columns",
    {
    "Client Sub per Recruiter",
    "Sourcing Sub per Recruiter",
    "Average Sourcing Subs",
    "Average Client Subs",
    "Interviews",
    "Offers",
    "Temp Starts",
    "Contract Billable HC",
    "AWGP Run Rate"
    },
    "Attribute",
    "Value"
    ),
    Group = Table.Group(
    Unpivot,
    {"Attribute"},
    {
    {"2-Week Average", each Number.Round(List.Sum(List.FirstN(_[Value], 2)) / 2, 2), Int64.Type},
    {"4-Week Average", each Number.Round(List.Sum(List.FirstN(_[Value], 4)) / 4, 2), Int64.Type},
    {"6-Week Average", each Number.Round(List.Sum(List.FirstN(_[Value], 6)) / 6, 2), Int64.Type},
    {"8-Week Average", each Number.Round(List.Sum(List.FirstN(_[Value], 8)) / 8, 2), Int64.Type}
    }
    )
    in
    Group