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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric 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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.