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
rogerdea
Helper IV
Helper IV

Moving Avg not working as intended

Hello

 

I have done a moving 30 day average for the past 30 days, but i am not getting the expected results.  This is my DAX:

 

 

4 Week Avg (Proc Date) = 
CALCULATE(
            COUNT(Metadata[IncidentId]), 
            DATESINPERIOD(Metadata[Completed Date],LASTDATE(Metadata[Completed Date]),-30,DAY)
         )
/ 
CALCULATE(
            DISTINCTCOUNT(Metadata[Week Completed]),
            DATESINPERIOD(Metadata[Completed Date],LASTDATE(Metadata[Completed Date]),-30,DAY)
         )

 

 

But my 4 week average is the same figure as number of records each week.

 

rogerdea_0-1626762801304.png

 

I can't upload the data because of confidentiality, but have i done anything obviously wrong?

Thanks

 

1 ACCEPTED SOLUTION

So i think i found  better way to do it which is working fine:

 

Processing (14 day moving avg) = 
AVERAGEX( 
          DATESBETWEEN(Metadata[Completed Date], MAX(Metadata[Completed Date]) -14, MAX(Metadata[Completed Date])),
          CALCULATE(COUNT(Metadata[IncidentId]))
          )

 

Note - i decided to change to a 14 day moving average but the logic works. 

View solution in original post

4 REPLIES 4
rogerdea
Helper IV
Helper IV

Actually the number of records is not calculating correctly either.  So both calulations are not correct.

Fowmy
Super User
Super User

@rogerdea 

Can you create two measures for each part of your calculations and check the results?

CALCULATE(
            COUNT(Metadata[IncidentId]), 
            DATESINPERIOD(Metadata[Completed Date],LASTDATE(Metadata[Completed Date]),-30,DAY)
         )
CALCULATE(
            DISTINCTCOUNT(Metadata[Week Completed]),
            DATESINPERIOD(Metadata[Completed Date],LASTDATE(Metadata[Completed Date]),-30,DAY)
         )




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy  great suggestion, i can see the problem:

 

It's calculating the number of weeks as 1.  (column named 2)

rogerdea_0-1626764325782.png

 

I definitely have more than one distinct week in my data looking over the past 30 days:

 

rogerdea_1-1626764437273.png

 

any ideas what i did wrong?

So i think i found  better way to do it which is working fine:

 

Processing (14 day moving avg) = 
AVERAGEX( 
          DATESBETWEEN(Metadata[Completed Date], MAX(Metadata[Completed Date]) -14, MAX(Metadata[Completed Date])),
          CALCULATE(COUNT(Metadata[IncidentId]))
          )

 

Note - i decided to change to a 14 day moving average but the logic works. 

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.