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
Anonymous
Not applicable

Moving Average with fixed first date

Dear Community,

 

How can I count a kind of a moving averge that works likes this: First date is fixed and the average is counted on adding every next date's data as it procceeds. For example:

I have   Date  

 ABCDE
1IDDate WeightsBox weightWeight / pack
2111101/01/202242513
3111202/01/20224.52312.7
4112505/01/20224.425.613.1
5114306/01/20224.225.212.4
7115609/01/20224.523.813.3

 

So, now the aevarge is counted like this in excel: IF(AND(A1<>"",C1<>"-"),ROUND(AVERAGE($E$1:E1),1),"-") .

 

The part that confuses me is that fixing the first value and calculateing the average of that fixed value plus every next one as it goes.

 

Thank you for your help!

1 ACCEPTED SOLUTION
v-kkf-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please try the following measure:

 

Moving Average = 
VAR FirstID = FIRSTNONBLANKVALUE ( 'Table'[Date], MAX ( 'Table'[ID] ) )
VAR firstWeight = FIRSTNONBLANKVALUE ( 'Table'[Date], SUM ( 'Table'[Weights] ) )
VAR Ave =
    CALCULATE (
        AVERAGE ( 'Table'[Weight / pack] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Date] <= MAX ( 'Table'[Date] ) )
    )
RETURN
    IF ( AND ( FirstID <> BLANK (), ISNUMBER ( firstWeight ) ), Ave, "-" )

vkkfmsft_0-1652408061156.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
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

1 REPLY 1
v-kkf-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please try the following measure:

 

Moving Average = 
VAR FirstID = FIRSTNONBLANKVALUE ( 'Table'[Date], MAX ( 'Table'[ID] ) )
VAR firstWeight = FIRSTNONBLANKVALUE ( 'Table'[Date], SUM ( 'Table'[Weights] ) )
VAR Ave =
    CALCULATE (
        AVERAGE ( 'Table'[Weight / pack] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Date] <= MAX ( 'Table'[Date] ) )
    )
RETURN
    IF ( AND ( FirstID <> BLANK (), ISNUMBER ( firstWeight ) ), Ave, "-" )

vkkfmsft_0-1652408061156.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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