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! Request now

Reply
MITHUN_NAIR
Regular Visitor

Need Help with Running Total for Last 12 Months

MITHUN_NAIR_0-1687198719910.png

 

Hi All, Need help in Creating the Running Total for the Last 12 Months . 

Like 3,5,6,9,12,14,18,20,21,23

 

I have created below code but it is not working 

Running Total =
Var EndDate =
    Calculate(MAX(Table1[dateofjoining] ),All('Date'))
VAR StartDate =
    Date(Year(EndDate),MONTH(EndDate)-12,Day(EndDate))

Var Last12Months=Filter(
           'Date',
            'Date'[Date]>=StartDate && 'Date'[Date]<=EndDate)
           
Var a = MAX('Date'[Date])
Var b = CALCULATE(MIN('Date'[Date]),ALLSELECTED('Date'))
Var Result=CALCULATE(DISTINCTCOUNT(Table1[person]),FILTER(Last12Months,[Date]>=b &&[Date]<=a))
RETURN
   Result

 

Am not able to use the ALL function to Remove Filter from for Table Expression  i.e. Last12Months Variable from Result Variable

1 REPLY 1
Jihwan_Kim
Super User
Super User

Hi,

I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

Jihwan_Kim_1-1687232308022.png

 

Jihwan_Kim_2-1687233120342.png

 

Person count: = 
COUNTROWS( VALUES(Data[Person]) )

 

Expected result measure: =
VAR _slicerselect =
    MAX ( 'Slicer table'[Month-Year sort] )
VAR _lasttwelvemonths =
    SUMMARIZE (
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Date] <= EOMONTH ( _slicerselect, 0 )
                && 'Calendar'[Date] > EOMONTH ( _slicerselect, -12 )
        ),
        'Calendar'[Month-Year],
        'Calendar'[Month-Year sort]
    )
VAR _result =
    CALCULATE (
        SUMX ( VALUES ( 'Calendar'[Month-Year sort] ), [Person count:] ),
        WINDOW (
            1,
            ABS,
            0,
            REL,
            _lasttwelvemonths,
            ORDERBY ( 'Calendar'[Month-Year sort], ASC )
        )
    )
RETURN
    _result

 

 

 

 

 

 


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.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

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!

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.