Daily average of previous 5 Years / Problem with leap year

glasi

New Member
Joined
Nov 27, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello everybody!

As a newbie, I'm approaching Power Query and Power Pivot. After the initial successes, I am now stuck with a problem and hope for expert advice.

I've already added my data to the Power Pivot data model.

DateStorageLevel
01/01/2015165.31
01/02/2015164.98
01/03/2015163.43
...
11/26/2020221.98
11/27/2020220.69

I know want to calculate a power pivot measure which returns the daily average of the previous 5 years, i. e. the average for each individual day in the period 2015 - 2019.

The following approach mathematically gives the correct results...

Power Query:
=AVERAGEX (
    SUMMARIZE (
        FILTER (
            Table1; (
                Table1[Date] >= DATE(2015;1;1)
                && Table1[Date] <= DATE(2019;12;31)
            )
        );
        Table1[Date]    
    );
    CALCULATE ( SUM ( Table1[StorageLevel] ) )
)

... however, the leap day 29th February is distorting my results. While 5 values are used to calculate the average for each day, there is only 1 value for February 29 in the period 2015-2019.

1606504835279.png


Does anyone of you know a code snippet how I can replace the average value for the leap day 29th February with the value of the previous day?

Many thanks in advance.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
the results are not distorted, they are correct. The Feb 29th average is correct. What do you want to happen? You have choices
you could do the calculation based on day of year, so in a leap year you will have an extra day at the end (day 366), so that will just move the problem
you could ignore this date
you could combine it with 1 March.
all of the above are less correct, but would remove the outlier. It depends what you want to do. Frankly I would just filter it out. It is easiest and no more right or wrong than the other options. Just wrap everything inside another calculate where Date <> 29 Feb
 
Upvote 0
Ok, then I'll filter out all leap days in my Power Query code.

Final result will look like this then...

1606517054445.png
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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