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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
LaurieS
Helper I
Helper I

6Mo Rolling Sum using sequential months, exclulding months with no data

I've been trying various DAX statements to obtain a rolling 6 month sum, only including months that have data. So far, I'm unable to get it working properly. If I only filter the date slicer, the measure works correctly, as the data is saturated enough to not have any blank months of data.

LaurieS_2-1706300434284.pngLaurieS_0-1706299975852.png

But if I filter on a country that doesn't have data every month, then it's still using every month to sum the last 6, not just the ones with data.

LaurieS_1-1706300030672.png

For example in this scenario Jan-20 should be 10, skipping Nov-19 since there's no data. I would appreciate any feedback. This is the example of the DAX I'm currently using for this:

 

6MoRollingSum_Runs3 =
VAR DateFilter =
    DATESINPERIOD ( CalendarTable[CalendarDate], MAX ( CalendarTable[CalendarDate] ), -6, MONTH )
VAR DateFilterMin =
    MINX ( DateFilter, CalendarTable[CalendarDate] )
VAR DateFilterNumMonths =
    COUNTROWS (
        CALCULATETABLE (
            SUMMARIZE ( CalendarTable, CalendarTable[Year], CalendarTable[Month] ),
            DateFilter
        )
    )
VAR EarliestDateInData =
    CALCULATE ( MIN ( 'Table'[TransDate]), ALL ( 'Table ),'Table'[NonZero]= 1 )
RETURN
    IF (
        AND ( EarliestDateInData <= DateFilterMin, DateFilterNumMonths >= 6 ),
        CALCULATE ( SUM ('Table'[NonZero]), DateFilter )
    )

 

This is not the only DAX snippets I've used. I think I've tried at least 20+ various community suggestions but not finding any that actually work the way I need it to.

 

Thanks for your input!

 

 

 



1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file whether it suits your requirement.

 

Jihwan_Kim_0-1706331052997.png

 

Jihwan_Kim_1-1706331432845.png

 

WINDOW function (DAX) - DAX | Microsoft Learn

 

Sales measure: = 
SUM( Sales[Sales] )

 

expected result measure: = 
CALCULATE (
    [Sales measure:],
    WINDOW (
        -5,
        REL,
        0,
        REL,
        SUMMARIZE (
            ALLSELECTED ( Sales ),
            'Calendar'[Year-Month sort],
            'Calendar'[Year-Month]
        ),
        ORDERBY ( 'Calendar'[Year-Month sort], ASC )
    )
)

 


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

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file whether it suits your requirement.

 

Jihwan_Kim_0-1706331052997.png

 

Jihwan_Kim_1-1706331432845.png

 

WINDOW function (DAX) - DAX | Microsoft Learn

 

Sales measure: = 
SUM( Sales[Sales] )

 

expected result measure: = 
CALCULATE (
    [Sales measure:],
    WINDOW (
        -5,
        REL,
        0,
        REL,
        SUMMARIZE (
            ALLSELECTED ( Sales ),
            'Calendar'[Year-Month sort],
            'Calendar'[Year-Month]
        ),
        ORDERBY ( 'Calendar'[Year-Month sort], ASC )
    )
)

 


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.

Thank you so much!! Works like a charm. I hadn't tried any DAX using the WINDOW function before. Very clean.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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