Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Alex_LevelUp
Frequent Visitor

Average of Top 5 days over the past 365 days (1 year)

Hello,

 

I'm stuck trying to calculate the average of my 5 highest production days over the past 365 days, or technically it would be 365 days from the last production entry date. 

 

Currently, I believe I'm able to calculate the rolling average of all production over the last 365 days, but I'm stuck identifying the top 5 days and calculating the average of those days. 

I have the below measure so far.  As a FYI, [TPAOH] is the metric I'm trying to capture the average of the top 5 on. There are only two tables I'm using, which are daily production and a dates table.

 

PROD 5=
VAR NumOfMonths = 12
VAR LastCurrentDate=
    MAX(Dates[Date])
VAR Periodex =
    DATESINPERIOD(Dates[Date], LastCurrentDate, -12, MONTH)
VAR Result =
    CALCULATE(
        AVERAGEX(
            VALUES('Dates'[Date]), [TPAOH]), Periodex)
VAR FirstDateInPeriod = MINX(Periodex, 'Dates'[Date])
VAR LastDatewithProd = MAX('Daily Production'[Date])
RETURN
    IF(FirstDateInPeriod <= LastDatewithProd, Result)
2 REPLIES 2
amitchandak
Super User
Super User

@Alex_LevelUp , try measures like

 

M1 = sum(Table[Values])

 

Top 5 =

CALCULATE( AverageX(Values('Date'[Date]), [M1]) ,TOPN(5,allselected('Date'[Date]), [M1] ,DESC),values('Table'[Date]),
DATESINPERIOD('Date'[Date ],MAX(Sales[Sales Date]),-12,MONTH) )

 

or

 

Top 5 =

CALCULATE(
CALCULATE( AverageX(Values('Date'[Date]), [M1]) ,TOPN(5,allselected('Date'[Date]), [M1] ,DESC),values('Table'[Date])),
DATESINPERIOD('Date'[Date ],MAX(Sales[Sales Date]),-12,MONTH) )

This is giving me a top 5 average which is great, but it still seems to only calculate the average of the top 5 based on the selection criteria for date. Ex. it will show the top 5 average based off two weeks if I filter for two weeks. If I show all dates in a table it will just show me the same total of that day since it's just dividing it by one.

Is there a way to show the top 5 average of the past 365 days based off a selected date?

Thanks!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors