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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Average of previous 4 week starts

Hi All,

 

I have data like below for every week start and hours.

NameWeek StartHours
A02/10/202030
A02/17/202040
A02/24/202025
A03/02/202040
A03/09/20200
A03/16/20200
A03/23/20200
A03/30/20200
A04/06/20200

 

So the requirement is. If Hour is zero, then calculate average Hours of previous 4 week starts.

Thanks in advance!!

1 ACCEPTED SOLUTION
V-pazhen-msft
Community Support
Community Support

@Anonymous 

Do you mean you want to calculate the previous 4 weeks average by Name? If so try this: 

1. create the weeknumber column:

Weeknumber = WEEKNUM('Table'[Week Start])

 

2. create the result column 

Column =
var averagehour = CALCULATE(AVERAGE('Table'[Hours]),ALLEXCEPT('Table','Table'[Name]),'Table'[Weeknumber]>=EARLIER('Table'[Weeknumber])-4)
return IF([Hours]=0,averagehour)
 
 
Paul Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
V-pazhen-msft
Community Support
Community Support

@Anonymous 

Do you mean you want to calculate the previous 4 weeks average by Name? If so try this: 

1. create the weeknumber column:

Weeknumber = WEEKNUM('Table'[Week Start])

 

2. create the result column 

Column =
var averagehour = CALCULATE(AVERAGE('Table'[Hours]),ALLEXCEPT('Table','Table'[Name]),'Table'[Weeknumber]>=EARLIER('Table'[Weeknumber])-4)
return IF([Hours]=0,averagehour)
 
 
Paul Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
rajulshah
Super User
Super User

Hello @Anonymous,

Please create a calculated column as below:

Index = RANKX(WeekAverage,WeekAverage[Week Start],FIRSTDATE(WeekAverage[Week Start]),ASC,Dense)

And create a calculated column as below:

FinalHours = 
VAR Hours = SUM(WeekAverage[Hours])
VAR SelectedIndex = WeekAverage[Index]-4
VAR AveragePrevWeeks = CALCULATE(SUM(WeekAverage[Hours]),FILTER(WeekAverage,WeekAverage[Index]>=SelectedIndex))
VAR AverageWeek = IF(WeekAverage[Hours]=0,DIVIDE(AveragePrevWeeks,4),WeekAverage[Hours])
RETURN AverageWeek

 

Please let me know if this is not what you expect.

Anonymous
Not applicable

Sorry i have't provided correct data. It actually worked for the previous scenario. But i have attached actual input file where we have multiple names and dates. when i used same calculation it is producing different values. could you please provide solution where we have repeating names and dates.

Below is the actual data:

 

NameWeek StartHours
A02/10/20200
A02/17/20200
A02/24/20200
A03/02/20200
A03/09/20200
A03/16/20200
A03/23/20200
A03/30/20200
A04/06/20200
A04/13/20200
B04/20/20200
B04/27/20200
B05/04/20200
B05/11/20200
B05/18/20200
B05/25/20200
B06/01/20200
B06/08/20200
B06/15/20200
B06/22/20200
B06/29/20200
B07/06/20200
C07/13/20200
C07/20/20200
C07/27/20200
C08/03/20200
C08/10/20200

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.