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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jjkmd
Helper I
Helper I

Rolling 12 and All() together acting in unexpected way

I've summarized data into a simple table, that I'm trying to do the following:  Table and attempted link to pbix file below.

 

For a given month, find the sum of the last 12 months, for all(persons), who that month particular month have a Flag = Yes.

 

I use this formula

Rolling for all =
CALCULATE (
    [Sum Value],
    ALL ( 'Table'[Person] ),
    DATESINPERIOD ( 'Table'[Date], LASTDATE ( 'Table'[Date] ), -12, MONTH ),
    'Table'[Flag] = "Yes"
)

Here is the behavior I want:

I have a value of 1,000 for each month for each person in this test.  So, for each individual, the rolling 12 should be 12,000.

If in a given month, 5 people have a flag of 'yes', then I should have a value of 60,000 total - regardless of what flags they had in the last 12 months.

 

What actually happens:

The formula looks at the past 12 months and only includes a given month IF the flag = "yes".  So, someone with that flag for only 3 of the last 12 months would only contribute 3,000 to total.  I can see why it does that, but I don't want that.  I want the full 12 months rolling if the current month flag = "yes", irrespective of what the last 12 months had for a flag.

 

Put another way:  if there are 4 people with the flag = yes then it should show 48,000.  Then if the very next month 1 more person gets the flag = yes (5 total), then that same month it should jump to 60,000.  Instead, it jumps to 49,000.

 

Annotation 2019-10-13 174634.jpg

 

PersonDateValueFlag
COctober 20191000Yes
EOctober 20191000Yes
DOctober 20191000Yes
BOctober 20191000Yes
AOctober 20191000Yes
ESeptember 20191000Yes
DSeptember 20191000Yes
CSeptember 20191000Yes
BSeptember 20191000Yes
ASeptember 20191000Yes
CAugust 20191000Yes
EAugust 20191000Yes
DAugust 20191000Yes
BAugust 20191000Yes
AAugust 20191000Yes
EJuly 20191000Yes
DJuly 20191000Yes
CJuly 20191000Yes
BJuly 20191000Yes
AJuly 20191000Yes
EJune 20191000 
DJune 20191000Yes
CJune 20191000Yes
BJune 20191000Yes
AJune 20191000Yes
CMay 20191000Yes
EMay 20191000 
DMay 20191000Yes
BMay 20191000Yes
AMay 20191000Yes
DApril 20191000Yes
CApril 20191000Yes
EApril 20191000 
BApril 20191000Yes
AApril 20191000Yes
EMarch 20191000 
DMarch 20191000Yes
CMarch 20191000Yes
BMarch 20191000Yes
AMarch 20191000Yes
CFebruary 20191000Yes
EFebruary 20191000 
DFebruary 20191000Yes
BFebruary 20191000Yes
AFebruary 20191000Yes
EJanuary 20191000 
DJanuary 20191000Yes
CJanuary 20191000Yes
BJanuary 20191000Yes
AJanuary 20191000Yes
EDecember 20181000 
DDecember 20181000Yes
CDecember 20181000Yes
BDecember 20181000Yes
ADecember 20181000Yes
ENovember 20181000 
DNovember 20181000Yes
CNovember 20181000Yes
BNovember 20181000Yes
ANovember 20181000Yes
DOctober 20181000Yes
COctober 20181000Yes
EOctober 20181000 
BOctober 20181000Yes
AOctober 20181000Yes
ESeptember 20181000 
DSeptember 20181000Yes
CSeptember 20181000Yes
BSeptember 20181000Yes
ASeptember 20181000Yes
CAugust 20181000Yes
EAugust 20181000 
DAugust 20181000Yes
BAugust 20181000Yes
AAugust 20181000Yes
EJuly 20181000 
DJuly 20181000Yes
CJuly 20181000Yes
BJuly 20181000Yes
AJuly 20181000Yes
EJune 20181000 
DJune 20181000Yes
CJune 20181000Yes
BJune 20181000Yes
AJune 20181000Yes
EMay 20181000 
DMay 20181000Yes
CMay 20181000Yes
BMay 20181000Yes
AMay 20181000Yes
EApril 20181000 
DApril 20181000Yes
CApril 20181000Yes
BApril 20181000Yes
AApril 20181000Yes
EMarch 20181000 
DMarch 20181000Yes
CMarch 20181000Yes
BMarch 20181000Yes
AMarch 20181000Yes
EFebruary 20181000 
DFebruary 20181000Yes
CFebruary 20181000Yes
BFebruary 20181000Yes
AFebruary 20181000Yes
EJanuary 20181000 
DJanuary 20181000Yes
CJanuary 20181000Yes
BJanuary 20181000Yes
AJanuary 20181000Yes

 

 

https://1drv.ms/u/s!AlCaI3WpECWQgbsXLUxAXeUrQpSAcQ

 

pbix attempt at sharing

 

 

1 REPLY 1
sturlaws
Resident Rockstar
Resident Rockstar

Hi,

 

different ways of doing this, here is one method:

 

First create a new column called YearMonthNum like this

YearMonthNum =
 ( YEAR ( 'Table'[Date] ) - 2010 ) * 12
    + MONTH ( 'Table'[Date] )

which generates a sequential number of month and year, starting with 1 at january 2010. 2010 is somewhat arbitrary chosen. The beauty of such a column is that you can just add or subtract a number change a period.

 

Then change your measure to this:

Rolling for all =
VAR _tab =
    CALCULATETABLE (
        VALUES ( 'Table'[Person] );
        FILTER (
            ALL ( 'Table' );
            'Table'[Flag] = "Yes"
                && 'Table'[YearMonthNum] <= MIN ( 'Table'[YearMonthNum] )
                && 'Table'[YearMonthNum]
                    >= MIN ( 'Table'[YearMonthNum] ) - 11
        )
    )
RETURN
    CALCULATE (
        [Sum Value];
        FILTER (
            ALL ( 'Table' );
            'Table'[Person] IN _tab
                && 'Table'[YearMonthNum] <= MIN ( 'Table'[YearMonthNum] )
                && 'Table'[YearMonthNum]
                    >= MIN ( 'Table'[YearMonthNum] ) - 11
        )
    )

where the variable finds all Persons with "Yes" in the last 12 months, and then main part looks at all those and sums over the last 12 months.

cheers,
Sturla

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors