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

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
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,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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