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
ryan_b_fiting
Post Patron
Post Patron

Calculate weekly average based on selected time periods

Hello Community - 

 

I am looking to get a weekly average for the most recent  3 week period based on whatever time period is selected.

I also need to be able to get that average by users that are sliced or filtered on.

Below is a small data set sample and there results I am expecting for the period of 1/1/21-1/22/21.

 

User IDSale DatePO Count Period StartPeriod End
1231/1/2021100 1/1/20211/22/2021
1231/8/2021200   
2341/1/202140   
2341/8/2021500 User3 Wk Avg
2341/15/2021600 Overall  1,570.00
2341/22/2021300 123       66.67
3451/22/2021900 234     466.67
3551/8/2021750 345     300.00
3551/15/2021700 355     736.67
3551/22/2021760 399              -  
3991/1/2021600   

 

So for the example above, I would want the sliced date range (1/1/21-1/22/21) to remain the same for all users.  So if I select the use 399, I should get 0 as my average because there is no PO's in the 3 week average range (most recent 3 weeks would be 1/8/21-1/22/21).

 

Any help is appreciated with this.  I have been going in circles on it, and I have a feeling it is something relatively easy that I am just missing because I have been staring at it for so long.

 

Thanks Commuity!

Ryan

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi, @ryan_b_fiting 

Please check the below picture and the sample pbix file's link down below.

 

Picture4.png

 

 

Avg 3weeks =
VAR latestweeknumber =
MAX ( 'Calendar'[Week of Year] )
VAR threeweeksperiod = latestweeknumber - 2
RETURN
DIVIDE (
CALCULATE (
SUM ( Data[PO Count] ),
FILTER (
ALL ( 'Calendar' ),
'Calendar'[Week of Year] >= threeweeksperiod
&& 'Calendar'[Week of Year] <= latestweeknumber
)
),
3
)

 

 

https://www.dropbox.com/s/9jm1dau86n2hdfc/fiting.pbix?dl=0 

 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi, @ryan_b_fiting 

Please check the below picture and the sample pbix file's link down below.

 

Picture4.png

 

 

Avg 3weeks =
VAR latestweeknumber =
MAX ( 'Calendar'[Week of Year] )
VAR threeweeksperiod = latestweeknumber - 2
RETURN
DIVIDE (
CALCULATE (
SUM ( Data[PO Count] ),
FILTER (
ALL ( 'Calendar' ),
'Calendar'[Week of Year] >= threeweeksperiod
&& 'Calendar'[Week of Year] <= latestweeknumber
)
),
3
)

 

 

https://www.dropbox.com/s/9jm1dau86n2hdfc/fiting.pbix?dl=0 

 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


samdthompson
Memorable Member
Memorable Member

Hello, try this instead, you might need to change table names etc:

 

CALCULATE(

AVERAGEX(

 

    SUMMARIZE('Table','Table'[Date],"PO", CALCULATE(COUNT('Table'[PO ID])))

    ,[PO]),

   FILTER(ALL('Table'[Date]),

   'Table'[Date] <= MAX('Table'[Date]) &&

   'Table'[Date] > (MAX('Table'[Date])-21)

   )

)

 

// if this is a solution please mark as such. Kudos always appreciated.
samdthompson
Memorable Member
Memorable Member

Hello, try something like this (have assumed you already have a PO count measure):

 

=CALCULATE([PO_Count],DATESINPERIOD('Date'[Date],LASTDATE('Date'[Date]),-21,DAY))
 
// if this is a solution please mark as such. Kudos always appreciated.

@samdthompson thanks for the reply.  This does not appear to provide the correct solution. 

It seems that whenever I select a user the dates always get adjusted to the users date range for the average.

Example: I have all of 2021 selected (latest sale date is 1/22/21), when I select user 399, it is still giving me a 200 average when it should be 0 because user 399 has 0 PO's in the 3 Week Average range.

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.