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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
daniwill882
Frequent Visitor

Referencing Part of a Calendar Tablein a Moving Average Measure

Hi,

 

I'm currently working on a report to bring together all of our main datasets. This includes a page per dataset and then one to combine relevant data. I've created a calendar table to link the date element of all datasets together. The issue i'm having is with the moving average measure for one dataset, this is because there is a year's less data. All other datasets start on 04/01/2015 while this one only goes back to 04/01/2016. This is causing the April 2016 moving average to include previous months as if the value is 0Capture.PNG.

 

 

 

 

 

 

 

 

 

The DAX i'm using for moving average is:

 

Confirm Moving Average = IF(COUNTROWS(VALUES('Calendar'[MonthNumber]))=1,CALCULATE([Count of Confirm Records]/COUNTROWS(VALUES('Calendar'[MonthNumber])),DATESBETWEEN('Calendar'[Date],FIRSTDATE(PARALLELPERIOD('Calendar'[Date],-2,MONTH)),LASTDATE(PARALLELPERIOD('Calendar'[Date],0,MONTH))),ALL('Calendar')))

 

My question is, is there anything I can add into the DAX so that it only includes data from 04/01/2016 rather than the whole calendar dates column.

 

I'm relatively new to Power BI so any advice would be greatly appreciated.

1 ACCEPTED SOLUTION
Eric_Zhang
Microsoft Employee
Microsoft Employee

@daniwill882

What if you add a filter to the DAX? For further questions, please post some sample data(in plain text or file, we  can't copy from a snapshot) and expected output.

Confirm Moving Average =
IF (
    COUNTROWS ( VALUES ( 'Calendar'[MonthNumber] ) ) = 1,
    CALCULATE (
        [Count of Confirm Records] / COUNTROWS ( VALUES ( 'Calendar'[MonthNumber] ) ),
        DATESBETWEEN (
            'Calendar'[Date],
            FIRSTDATE ( PARALLELPERIOD ( 'Calendar'[Date], -2, MONTH ) ),
            LASTDATE ( PARALLELPERIOD ( 'Calendar'[Date], 0, MONTH ) )
        ),
        FILTER ( 'Calendar', 'Calendar'[Date] >= DATE( 2016, 4, 1 ) )
    )
)

View solution in original post

2 REPLIES 2
Eric_Zhang
Microsoft Employee
Microsoft Employee

@daniwill882

What if you add a filter to the DAX? For further questions, please post some sample data(in plain text or file, we  can't copy from a snapshot) and expected output.

Confirm Moving Average =
IF (
    COUNTROWS ( VALUES ( 'Calendar'[MonthNumber] ) ) = 1,
    CALCULATE (
        [Count of Confirm Records] / COUNTROWS ( VALUES ( 'Calendar'[MonthNumber] ) ),
        DATESBETWEEN (
            'Calendar'[Date],
            FIRSTDATE ( PARALLELPERIOD ( 'Calendar'[Date], -2, MONTH ) ),
            LASTDATE ( PARALLELPERIOD ( 'Calendar'[Date], 0, MONTH ) )
        ),
        FILTER ( 'Calendar', 'Calendar'[Date] >= DATE( 2016, 4, 1 ) )
    )
)

Thank you, this works perfectly. I will do so in future posts, thanks for the advice.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

Top Solution Authors