Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

3 Year Average per Month

Hi All,

 

I am trying to work out an average of X Value over the previous 3 years, not including the current year, by month and then filter by site. In my actual data I have 30+ sites.

My table looks like this:

SiteMonthMonth NoYearDateAverage Windspeed
Bicker FenJan1202401/01/20247.912230769
Bicker FenFeb2202401/02/20246.938166667
Bicker FenMar3202401/03/20246.656153846
Bicker FenJan1202101/01/20216.51
Bicker FenFeb2202101/02/20217.2
Bicker FenMar3202101/03/20216.4
Bicker FenJan1202201/01/20226.4
Bicker FenFeb2202201/02/20229.5
Bicker FenMar3202201/03/20225.7


I've tried  a few different ways like average for windspeed where year is <2024 etc but to no luck.

 

Thanks in Advance,
M

  • Hi Anonymous 

     

    Try with this measure

    AverageWindspeedLast3Years = 
    CALCULATE(
        AVERAGEX(
            VALUES('Table'[Date]),
            'Table'[Average Windspeed]),
        FILTER(
            'Table',
            'Table'[Year] < YEAR(TODAY()) &&
            'Table'[Year] >= YEAR(TODAY()) - 3),
        ALLEXCEPT('Table', 'Table'[Site], 'Table'[Month], 'Table'[Month No])
    )

     

    Let me know if it works

3 Replies

  • Hi Anonymous 

     

    Try with this measure

    AverageWindspeedLast3Years = 
    CALCULATE(
        AVERAGEX(
            VALUES('Table'[Date]),
            'Table'[Average Windspeed]),
        FILTER(
            'Table',
            'Table'[Year] < YEAR(TODAY()) &&
            'Table'[Year] >= YEAR(TODAY()) - 3),
        ALLEXCEPT('Table', 'Table'[Site], 'Table'[Month], 'Table'[Month No])
    )

     

    Let me know if it works

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi suparnababu8,

      This worked perfectly! Thank you 🙂

  • Hi Anonymous 

    Create a year table, relate it to your fact and create this measure:

    Average = 
    AVERAGEX (
        ADDCOLUMNS (
            SUMMARIZE (
                --create a table of years wherein the years are from current year -3 to current year - 1
                --note: if there are only two years in the current context, the sum of avg windspeed will be divided  by two as well, one if one...etc
                FILTER (
                    ALL ( Years ),
                    Years[Year]
                        >= MAX ( Years[Year] ) - 3
                        && Years[Year] < MAX ( Years[Year] )
                ),
                Years[Year]
            ),
            "Windspeed", CALCULATE ( SUM ( 'Table'[Average Windspeed] ) )
        ),
        [Windspeed]
    )
    

     

    Mar 2024: 5.7+6.4 = 12.1/2 = 6.05

    Please see attached sample pbix.