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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
bgierwi2
Advocate I
Advocate I

3 Day Rolling Average - DAX

I need to generate a DAX column for a 3 day rolling average of a car count.

Where it takes the entry from that day, and then whatever entries there are over the previous 2 days.

Averaged and then rounded down.

 

DateCar Count3 Day Rolling Average
1/4/2026104
1/3/202613
1/2/202614
1/1/202677

 

@AshokKunwar  - You had helped with other issues in the same setup.  Everything else worked, this is the last detail.

1 ACCEPTED SOLUTION
krishnakanth240
Skilled Sharer
Skilled Sharer

Hi @bgierwi2 

 

I have tested with Calculated column. Can you please try this from the below image

krishnakanth240_0-1768021472090.png

 

 

View solution in original post

8 REPLIES 8
AshokKunwar
Responsive Resident
Responsive Resident

Hii @bgierwi2 

If this solution worked for you, please Mark as Solution! It helps others in the community find this answer more easily. Cheers!

Breezhall
Regular Visitor

Breezhall_0-1768183222038.png

3 Day Rolling Average:=
VAR CurrentDate = MAX('表1'[date])
RETURN
AVERAGEX(
    FILTER(
       ALL('表1'),
        '表1'[date] >= CurrentDate -2 && '表1'[date] <= CurrentDate
    ),
    '表1'[count]
)
AshokKunwar
Responsive Resident
Responsive Resident

To create the table with Occurrence (1 to 1000) and the Stepped Penalty (500, 1000, etc.), follow these steps:

The Power Query (M) Solution

  1. ​In Power BI Desktop, go to Home > Transform Data.
  2. ​Go to Home > New Source > Blank Query.
  3. ​Open the Advanced Editor and paste the following code:

​<!-- end list -->

let
    // 1. Generate a list from 1 to 1000
    Source = {1..1000},
    
    // 2. Convert that list into a table
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    
    // 3. Rename the column to Occurrence
    #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Occurrence"}}),
    
    // 4. Change type to Int64
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Occurrence", Int64.Type}}),
    
    // 5. Add the Custom Penalty Logic
    #"Added Penalty" = Table.AddColumn(#"Changed Type", "Penalty", each 
        if [Occurrence] <= 2 then 500 
        else 500 + (Number.IntegerDivide([Occurrence] - 3, 3) + 1) * 500
    ),
    
    // 6. Set Currency Type
    #"Final Type" = Table.TransformColumnTypes(#"Added Penalty",{{"Penalty", Currency.Type}})
in
    #"Final Type"

 

Summary for the Community

​Using Number.IntegerDivide in Power Query allows you to create complex, non-linear sequences that are baked into your data schema. This keeps your DAX measures clean and focused solely on calculations rather than data generation.

 

If this Power Query script successfully builds your 1000-row penalty table, please mark this as the "Accepted Solution"!

krishnakanth240
Skilled Sharer
Skilled Sharer

Hi @bgierwi2 

 

I have tested with Calculated column. Can you please try this from the below image

krishnakanth240_0-1768021472090.png

 

 

@krishnakanth240 

 

That worked!

Thank you!!!

danextian
Super User
Super User

Hi @bgierwi2 

Assuming you are using a dedicated dates table (which is the best practice), create this measure below:

Roling 3 Days Average = 
VAR _period =
    DATESINPERIOD ( Data[Date], MAX ( 'Dates'[Date] ), -3, DAY )
RETURN
    CALCULATE (
        AVERAGEX ( VALUES ( 'Dates'[Date] ), [Total Revenue] ),
        _period,
        REMOVEFILTERS ( 'Dates' )
    )

danextian_0-1768020733329.png

 

REMOVEFILTERS is necessary if the dates table has not been marked as such.

Please see the attached sample pbix.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
cengizhanarslan
Memorable Member
Memorable Member

Please try the measure below:

 

3 Day Rolling Avg  =
VAR CurrentDate = SELECTEDVALUE ( Cars[Date] )
VAR Window =
    FILTER (
        ALL ( Cars ),
        Cars[Date] <= CurrentDate
            && Cars[Date] > CurrentDate - 3
    )
RETURN
ROUNDDOWN (
    AVERAGEX ( Window, CALCULATE ( SUM ( Cars[Car Count] ) ) ),
    0
)

 

If you have a proper Calendar table, you can use that in your measure instead.

_________________________________________________________
If this helped, ✓ Mark as Solution | Kudos appreciated
Connect on LinkedIn

@cengizhanarslan 

 

bgierwi2_1-1768020816371.png

 

I am getting an error on the variable "Window" saying the parameter is not the correct type.

The "Count Date" is formatted as a date.

The "Total Cars Actual" (the value I am averaging) is formatted as a decimal number that isn't summarized.

"Ineos Count" is the data source

 

Is there something I need to change?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

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.