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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
jconte12
Frequent Visitor

Rolling 5 Day Average

Hello,

I have an issue with a rolling average I created with DAX in a line chart.  The first 4 days are deflated because it's still thinking I want a 5 day average for the first 1, 2, 3, and 4 days... 

 

jconte12_0-1648752440182.png

 

Here is the DAX:

Rolling Avg =
VAR NumDays = 5 // Days Variable
VAR AvgQuantity =
CALCULATE(SUM('Cons TTL by Day'[QTY_SHIP_ATOMIC]),
FILTER(ALLSELECTED('Cons TTL by Day'),
'Cons TTL by Day'[SELL_DAY_RANK] > MAX('Cons TTL by Day'[SELL_DAY_RANK]) - NumDays &&
'Cons TTL by Day'[SELL_DAY_RANK] <= MAX('Cons TTL by Day'[SELL_DAY_RANK])))
RETURN
AvgQuantity/NumDays
 
 
Any ideas?

 

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

Hi  @jconte12 ,

I created some data:

vyangliumsft_0-1649214739290.png

Here are the steps you can follow:

1. Create calculated column.

rank = RANKX(ALL('Table'),'Table'[date],,ASC)
mod =
var _mod=MOD('Table'[rank],5)
return
IF(
    _mod=1,1,0)
Group =
CALCULATE(SUM('Table'[mod]),FILTER(ALL('Table'),'Table'[date]<=EARLIER('Table'[date])))

vyangliumsft_1-1649214739291.png

2. Create measure.

Measure =
var _1=MAX('Table'[Date])
return
AVERAGEX(
    FILTER(
        SUMMARIZE(ALL('Table'),
        'Table'[Date],'Table'[Group],
        "Avg value",AVERAGE('Table'[amount])),
        'Table'[Date]<=_1&&'Table'[Group]=MAX('Table'[Group])),
        [Avg value])

3. Result:

vyangliumsft_2-1649214739293.png

 

Best Regards,

Liu Yang

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

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @jconte12 ,

I created some data:

vyangliumsft_0-1649214739290.png

Here are the steps you can follow:

1. Create calculated column.

rank = RANKX(ALL('Table'),'Table'[date],,ASC)
mod =
var _mod=MOD('Table'[rank],5)
return
IF(
    _mod=1,1,0)
Group =
CALCULATE(SUM('Table'[mod]),FILTER(ALL('Table'),'Table'[date]<=EARLIER('Table'[date])))

vyangliumsft_1-1649214739291.png

2. Create measure.

Measure =
var _1=MAX('Table'[Date])
return
AVERAGEX(
    FILTER(
        SUMMARIZE(ALL('Table'),
        'Table'[Date],'Table'[Group],
        "Avg value",AVERAGE('Table'[amount])),
        'Table'[Date]<=_1&&'Table'[Group]=MAX('Table'[Group])),
        [Avg value])

3. Result:

vyangliumsft_2-1649214739293.png

 

Best Regards,

Liu Yang

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

davehus
Memorable Member
Memorable Member

Hi @jconte12 , Here's another example for moving average if that might help?

 

5 Day MA = CALCULATE(AVERAGE(SUM(Measure)),
DATESINPERIOD('Cons TTL by Day'[SELL_DAY_RANK] , LASTDATE('Cons TTL by Day'[SELL_DAY_RANK]), -5, DAY))

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.