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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! 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
Community Champion
Community Champion

@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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.