Average Weekly Usage

DanniiMarie

New Member
Joined
May 21, 2018
Messages
30
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
  6. 2011
  7. 2010
  8. 2007
  9. 2003 or older
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
I need to find the correct syntax for a Power Query formula that will calculate average weekly usage in my newly inserted custom column. Here's what I have in Excel:

September 2021

October 2021
November 2021Average Weekly Usage
19833280=(SUM(A2:C2)/(DAY(EOMONTH(A2,0))+DAY(EOMONTH(B2,0))+DAY(EOMONTH(C2,0))))*7
 
If your months are type text this should work. If they are type date or type number then it won't.

Power Query:
let
    tbl = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Source = Table.PromoteHeaders(tbl),
    months = List.LastN(Table.ColumnNames(Source),3),
    fullmonthweeks = List.Sum(List.Transform(months, each Date.DaysInMonth(Date.FromText(_))))/7,
    dt = DateTime.LocalNow(),
    weeks = if Date.FromText(months{2}) = #date(Date.Year(dt),Date.Month(dt),1) then 
            fullmonthweeks - Duration.Days(Date.EndOfMonth(dt) - dt)/7 else fullmonthweeks,
    Result = Table.AddColumn(Source, "Average Weekly Usage", each Number.Round(List.Sum(List.LastN(Record.ToList(_),3))/weeks,2))
in
    Result
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,213,544
Messages
6,114,249
Members
448,556
Latest member
peterhess2002

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top