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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
jdubs
Helper V
Helper V

Average of Cases created daily over the last 21 days

Hello,

 

I am trying to create a measure to show a count of the average case created count per day over the last 21 days. I had Copilot help with a calulation but it is not returning any data. Any help appreciated

 

Created_21avg = VAR __LAST_DATE = LASTDATE('Cases'[createdon].[Date]) RETURN AVERAGEX(DATESBETWEEN('Cases'[createdon].[Date], DATEADD(__LAST_DATE, -21, DAY), __LAST_DATE), CALCULATE(COUNTROWS('Cases')))

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @jdubs ,

 

Try to modify your formula like below:

Created_21avg = 
VAR __LAST_DATE =
    TODAY () - 1 -- Yesterday's date
RETURN
    AVERAGEX (
        DATESBETWEEN ( 'Cases'[createdon].[Date], __LAST_DATE - 21, __LAST_DATE ),
        CALCULATE ( COUNTROWS ( 'Cases' ) )
    )

 

vkongfanfmsft_0-1727941116990.png

 

Best Regards,
Adamk Kong

 

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

4 REPLIES 4
Anonymous
Not applicable

Hi @jdubs ,

 

Try to modify your formula like below:

Created_21avg = 
VAR __LAST_DATE =
    TODAY () - 1 -- Yesterday's date
RETURN
    AVERAGEX (
        DATESBETWEEN ( 'Cases'[createdon].[Date], __LAST_DATE - 21, __LAST_DATE ),
        CALCULATE ( COUNTROWS ( 'Cases' ) )
    )

 

vkongfanfmsft_0-1727941116990.png

 

Best Regards,
Adamk Kong

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hey Adamk,

 

Thank you. I think this is working! Just need to spot-check some data and will mark as solved!

jdubs
Helper V
Helper V

Hi Greg,

 

I'm getting a syntax error which I thought was due to the double quotes, which I changed to single quotes, but it still doesn't seem to like [_Count] in the formula.

 

Alternatively, I tried this formula which actually does return data however it only ever returns "1" no matter what i change the day range to e.g. 21 vs. 5

 

21Day_avg = AVERAGEX(KEEPFILTERS(VALUES('Cases'[createdon])), CALCULATE(COUNTROWS('Cases'), KEEPFILTERS('Cases'[createdon] > NOW() - 21)))

Greg_Deckler
Super User
Super User

@jdubs Try:

Created_21avg = 
  VAR __LastDate = MAX( 'Cases'[createdon] )
  VAR __MinDate = __LastDate - 21
  VAR __Table = 
    SUMMARIZE( 
      FILTER( 'Cases', 'Cases'[createdon] >= __MinDate && 'Cases'[createdon] <= __LastDate )
      [createdon], 
      "__Count", COUNTROWS( 'Cases' ) 
    )
  VAR __Result = AVERAGEX( __Table, [__Count] )
RETURN
  __Result
 


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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