Help with prior day value and rolling average for grouped data

  • Help with prior day value and rolling average for grouped data

    Posted by DSC Communities on April 14, 2020 at 12:20 pm
    • Claire Barr

      Member

      April 14, 2020 at 12:20 PM

      Hello, I’m a brand squeaky new user to Power Query M, and am struggling with creating two custom columns.

      I am working with the hourly dataset from The Weather Channel for multiple weather station locations, and I need return a table with the GasDate, Location, TempF, HDD, HDDs_DB (prior day HDD), and RA7_HDDs (rolling 7-day average HDD). For reference, HDD stands for Heating Degree Day, a term used in the gas industry to quantify how much colder it is than 65F.

      So far I have created this on my own (some irrelevant rows of code have been removed), which groups the data by gasdate and weatherstation location, averages the temperature in Fahrenheit, and calculates the HDD:

      let

      Source = Sql.Database(“WeatherDataTest”),
      dbo_TWChistorical = Source{[Schema=”dbo”,Item=”TWChistorical”]}[Data],
      #”Grouped Rows” = Table.Group(#”Removed Other Columns”, {“GasDate”, “Location”}, {{“TempF”, each List.Average([apparentTemperatureFahrenheit]), type number}}),
      #”Sorted Rows” = Table.Sort(#”Grouped Rows”,{{“GasDate”, Order.Descending}}),
      #”Rounded Off” = Table.TransformColumns(#”Sorted Rows”,{{“TempF”, each Number.Round(_, 0), type number}}),
      #”Added HDD” = Table.AddColumn(#”Rounded Off”, “HDD”, each if [TempF]<65 then 65-[TempF] else 0)
      in

      #”Added HDD”
      Ā 

      but now I need to add a column that returns the prior day’s HDD value, and a column for the rolling 7-day average of HDD, which I am struggling with due to the multiple locations.

      Thank you for any and all help.

      ——————————
      Claire B.
      Analyst
      ——————————

    • Greg Philps

      Member

      April 15, 2020 at 11:39 AM

      Hi Claire. As with many things in Power BI, there are often many ways of doing the same thing. One suggestion would be to create your HDDs_DB and RA7_HDD fields as calculated columns using DAX. Here’s a small sample that hopefully you’ll find useful. Good luck. Greg

      ——————————
      Greg Philps
      Power BI Consultant
      Ottawa ON Canada
      ——————————
      ——————————————-

    DSC Communities replied 5 years, 11 months ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

The discussion ‘Help with prior day value and rolling average for grouped data’ is closed to new replies.

Start of Discussion
0 of 0 replies June 2018
Now

Welcome to our new site!

Here you will find a wealth of information created for peopleĀ  that are on a mission to redefine business models with cloud techinologies, AI, automation, low code / no code applications, data, security & more to compete in the Acceleration Economy!