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
Jacob1832
Frequent Visitor

How to create a moving average for a merged table in Power Query

This is my data set, daily number of leads and sales. I need to create a rolling 4 week average conversion rate (meaning sales/leads) between the two. 
Jacob1832_0-1654528299460.png

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

- I created a sample pbix file like below.

- it is for creating a measure to provide 28days rolling average (daily avg.)

- I created a calendar table to use time-intelligent DAX function -> DATESINPERIOD & LASTDATE

 

Untitled.png

 

Rolling four weeks avg conversion: =
VAR rollingfourweeks =
    DATESINPERIOD ( 'Calendar'[Date], LASTDATE ( 'Calendar'[Date] ), -28, DAY )
VAR _condition =
    COUNTROWS ( rollingfourweeks ) >= 28
RETURN
    AVERAGEX ( rollingfourweeks, [Conversion measure:] )
        * DIVIDE ( _condition, _condition )

 


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.

View solution in original post

5 REPLIES 5
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

- I created a sample pbix file like below.

- it is for creating a measure to provide 28days rolling average (daily avg.)

- I created a calendar table to use time-intelligent DAX function -> DATESINPERIOD & LASTDATE

 

Untitled.png

 

Rolling four weeks avg conversion: =
VAR rollingfourweeks =
    DATESINPERIOD ( 'Calendar'[Date], LASTDATE ( 'Calendar'[Date] ), -28, DAY )
VAR _condition =
    COUNTROWS ( rollingfourweeks ) >= 28
RETURN
    AVERAGEX ( rollingfourweeks, [Conversion measure:] )
        * DIVIDE ( _condition, _condition )

 


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.

Hi, i have a change in the data set and it is instead by week.

Jacob1832_0-1654546822060.png

How would i calculate a 4 week moving average in this case?

Hi,

Thank you for your feedback.

Please check the below picture and the attached pbix file.

All measures are in the attached pbix file.

 

Untitled.png


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.

Hey, i have one more i need help with.
In this case, the rolling 4 week averagewould be a sum of the Actuals col grouped on the week and state cols, and then divided by 4. Any ideas? 

Jacob1832_0-1654638466425.png

 

Hi,

Thank you for your message, and please check the below picture and the attached pbix file.

I tried to create a new sample pbix file like below.

I am not sure how your data model looks like, and if the below is not what you are looking for, please share your sample pbix file's link here. And then I can try to look into it to have a more accurate solution.

 

Untitled.png

 

Rolling avg 4 wks: =
VAR _fourweekstable =
    DATESINPERIOD ( 'Calendar'[Date], LASTDATE ( 'Calendar'[Date] ), -28, DAY )
VAR _newtable =
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE (
                CALCULATETABLE ( 'Calendar', 'Calendar'[Date] IN _fourweekstable ),
                'Calendar'[Start of Week]
            ),
            "@actuals", [Actuals sum:]
        ),
        [@actuals] <> BLANK ()
    )
VAR _condition =
    COUNTROWS ( _newtable ) >= 4
RETURN
    AVERAGEX ( _newtable, [@actuals] ) * DIVIDE ( _condition, _condition )

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.

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.