DAX Formulas for Rolling 12 Month Ending Sums – DATESBETWEEN () and BLANK () Functions

AlphaJava

New Member
Joined
Jul 17, 2015
Messages
11
For the “12 Mo Rolling Enrollment”, I want to return blank for dates between dates 1/1/1991 and 11/1/1991 using the DATESBETWEEN () and blank () functions as shown in the formula below, but the formula is returning blanks for all dates. What am I doing wrong? Any help would be greatly appreciated. Thanks.

=IF(CALCULATE(SUM ( Population[Enrollment] ), DATESBETWEEN(Calendar[Month], DATE(1991,1,1), DATE(1991,11,1) )), BLANK(), (CALCULATE (
SUM ( Population[Enrollment] ),
FILTER (
ALL ( Calendar ),
Calendar[DateID]
>= MIN ( Calendar[DateID] ) - 11
&& Calendar[DateID] <= MAX ( Calendar[DateID] )
)
)
)
)
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I think the easiest way to produce a version of the "12 Month Rolling Enrollment" measure that returns blank for a particular date range is to remove that date range from the filter context, by wrapping the original measure inside another CALCULATE.

I can think of two ways to do it (first might be faster):

1.
Code:
=
[COLOR=#ff0000][B]CALCULATE ([/B][/COLOR]
    CALCULATE (
        SUM ( Population[Enrollment] ),
        FILTER (
            ALL ( Calendar ),
            Calendar[DateID]
                >= MIN ( Calendar[DateID] ) - 11
                && Calendar[DateID] <= MAX ( Calendar[DateID] )
        )
    )[B][COLOR=#ff0000],
    FILTER (
        Calendar,
        Calendar[Month] < DATE ( 1991, 1, 1 )
            || Calendar[Month] > DATE ( 1991, 11, 1 )
    )
)[/COLOR][/B]

2.
Code:
=
[COLOR=#ff0000][B]CALCULATE ([/B][/COLOR]
    CALCULATE (
        SUM ( Population[Enrollment] ),
        FILTER (
            ALL ( Calendar ),
            Calendar[DateID]
                >= MIN ( Calendar[DateID] ) - 11
                && Calendar[DateID] <= MAX ( Calendar[DateID] )
        )
    )[COLOR=#ff0000][B],[/B][/COLOR]
[COLOR=#ff0000][B]    FILTER ([/B][/COLOR]
[COLOR=#ff0000][B]       Calendar,[/B][/COLOR]
[COLOR=#ff0000][B]        NOT ([/B][/COLOR]
[COLOR=#ff0000][B]            CONTAINS ([/B][/COLOR]
[COLOR=#ff0000][B]                DATESBETWEEN ([/B][/COLOR]
[COLOR=#ff0000][B]                    Calendar[Month],[/B][/COLOR]
[COLOR=#ff0000][B]                    DATE ( 1991, 1, 1 ),[/B][/COLOR]
[COLOR=#ff0000][B]                    DATE ( 1991, 11, 1 )[/B][/COLOR]
[COLOR=#ff0000][B]                ),[/B][/COLOR]
[COLOR=#ff0000][B]                Calendar[DateID], Calendar[DateID][/B][/COLOR]
[COLOR=#ff0000][B]            )[/B][/COLOR]
[COLOR=#ff0000][B]        )[/B][/COLOR]
[COLOR=#ff0000][B]    )[/B][/COLOR]
[COLOR=#ff0000][B])[/B][/COLOR]
 
Upvote 0

Forum statistics

Threads
1,224,113
Messages
6,176,456
Members
452,728
Latest member
mihael546

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top