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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

Moving Average by Filtering Specific Column

Hi All,
Please note that  I am able to get the Last 7 days rolling Average for the below chart by Using the following Dax

Rifdhy_Hassen_0-1660021905463.png

Last 7 Days AVG = ([7 Days Moving SUM.]+0)/[# of Days]
7 Days Moving SUM. = CALCULATE([Total Fuel Consumed],DATESINPERIOD('Calendar'[Date],LASTDATE('Calendar'[Date]),-7,DAY))
# of Days = CALCULATE(DISTINCTCOUNT('Calendar'[Date]),DATESINPERIOD('Calendar'[Date],LASTDATE('Calendar'[Date]),-7,DAY))
 
Anyway, If I Filter the above chart by Specific Column then Last 7 Days AVG getting wrong
Rifdhy_Hassen_1-1660022054497.png

 

In this case, the Last 7 Days' AVG should be about 350/7,350/6,... so on

So how can I solve this?

 

Hoping for your support Guys...

Thanking a lot

Faithfully,

Rifdhy (+94770848216)

1 ACCEPTED SOLUTION
liuqi_pbi
Resolver III
Resolver III

Hi @Anonymous 

 

How about try these measures 

7 Days Moving SUM. =
CALCULATE (
    [Total Fuel Consumed],
    ALL ( 'Calendar'[Date] ),
    DATESINPERIOD ( 'Calendar'[Date], MAX ( 'Calendar'[Date] ), -7, DAY )
)
# of Days =
CALCULATE (
    DISTINCTCOUNT ( 'Calendar'[Date] ),
    ALL ( 'Calendar'[Date] ),
    DATESINPERIOD ( 'Calendar'[Date], MAX ( 'Calendar'[Date] ), -7, DAY )
)
Last 7 Days AVG = DIVIDE ( [7 Days Moving SUM.] + 0, [# of Days] )

 

In addition, did you use 'Calendar'[Date] column on X-axis in the visual? It is expected there. 

 

----------------------------------------------------------------------

If this reply helps solve the problem, please mark it as Solution! Kudos are appreciated too!

View solution in original post

1 REPLY 1
liuqi_pbi
Resolver III
Resolver III

Hi @Anonymous 

 

How about try these measures 

7 Days Moving SUM. =
CALCULATE (
    [Total Fuel Consumed],
    ALL ( 'Calendar'[Date] ),
    DATESINPERIOD ( 'Calendar'[Date], MAX ( 'Calendar'[Date] ), -7, DAY )
)
# of Days =
CALCULATE (
    DISTINCTCOUNT ( 'Calendar'[Date] ),
    ALL ( 'Calendar'[Date] ),
    DATESINPERIOD ( 'Calendar'[Date], MAX ( 'Calendar'[Date] ), -7, DAY )
)
Last 7 Days AVG = DIVIDE ( [7 Days Moving SUM.] + 0, [# of Days] )

 

In addition, did you use 'Calendar'[Date] column on X-axis in the visual? It is expected there. 

 

----------------------------------------------------------------------

If this reply helps solve the problem, please mark it as Solution! Kudos are appreciated too!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.