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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Rolling next 8-week average

Hi all,

 

I was struggling to figure out how to get an average demand from next 8 weeks, if the remainging weeks are less than 8 weeks, then calculate average based on the number of remaining weeks.

 

Simplfied dataset as below.

 

WeekDemandAvg_DemandRemark
2023/1/96564.875(45+45+66+75+75+75+70+68)/8
2023/1/164567.75(45+66+75+75+75+70+68+68)/8
2023/1/234571(66+75+75+75+70+68+68)/7
2023/1/306671.83333333(75+75+75+70+68+68)/6
2023/2/67571.2(75+75+70+68+68)/5
2023/2/137570.25(75+70+68+68)/4
2023/2/207568.66666667(70+68+68)/3
2023/2/277068(68+68)/2
2023/3/6686868
2023/3/1368  

 

Thanks in advance!

5 REPLIES 5
Padycosmos
Solution Sage
Solution Sage

Padycosmos_0-1673539161681.png

Hope this helps

FreemanZ
Super User
Super User

hi @Anonymous 

you may also try to add a column like this:

Avg_Demand2 = 
VAR _week = WEEKNUM([Week])
RETURN
AVERAGEX(
    FILTER(
        TableName, 
        WEEKNUM(TableName[Week])<=_week+8
            &&WEEKNUM(TableName[Week])>_week
    ),
    TableName[Demand]
)

 

it worked like this:

FreemanZ_0-1673534390184.png

Padycosmos_0-1673539161681.png

Hope this helps

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your data model looks like, but I assume you have a calendar table like below.

I tried to create a sample pbix file like below, and please check the below picure and the attached pbix file.

 

Jihwan_Kim_1-1673532451972.png

 

 

Jihwan_Kim_0-1673532430859.png

 

Demand measure: = 
SUM( Data[Demand] )

 

Expected result measure: =
VAR _condition =
    DIVIDE ( [Demand measure:], [Demand measure:] )
RETURN
    IF (
        HASONEVALUE ( 'Calendar'[Year-Wk] ),
        _condition
            * AVERAGEX (
                ADDCOLUMNS (
                    WINDOW (
                        1,
                        REL,
                        8,
                        REL,
                        ALL ( 'Calendar'[Year-Wk], 'Calendar'[Start of Week] )
                    ),
                    "@demand", [Demand measure:]
                ),
                [@demand]
            )
    )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

Hi @FreemanZ , @Jihwan_Kim 

 

Thanks for answerning my question.

However, I'm not sure why both of them do not display as I wish..

Probably, a little more about the dataset would help. It demonstrates weekly demand for each product by different region and destination from 2017 to present. I'd like to get an average demand when I collapse or expand the matrix.

Carol1207_0-1673537219868.png

Really appreciate your help.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 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.