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
snaraya
Helper II
Helper II

Rolling average and YTD for last 12 months

Hi everyone,

 

i have below data 

 

where the Result column is summation of all values available for that year-month & BU, its a measure which uses SUM function

 

now for each BU i need to create a dynamic rolling 12 month and YTD( will have slicer for BU in report) ,

for rolling data: 

so here for year 2021 , the rolling 12 month values will be empty , from 2022 the value should be average of last 12month i.e

 for Jan 2022 BU A= (sum of result from 2022 Jan-Feb2021)/12

for Feb 2022 BA A= (sum of result from 2022 Feb-March 2021)/12

 

similarly for each month and each BU

 

for YTD: 

the summation value will start fom year 2021.

for Jan 2021 BU A = (result Jan)/12

for Feb 2021 BU A = sum(result Jan2021+result feb 2021) /12 and so on till dec

 

 

 

for 2022 

for Jan 2022 BU A = (result Jan)/12

for Feb 2022 BU A = sum(result Jan 2022+result feb 2022) /12 similarly for each month till december for that year 

 

 

 

Reporting Period BUMonthMonth_number Result
2021AJanuary12949
2021BJanuary12304
2021AFebruary22988
2021BFebruary22370
2021AMarch32990
2021BMarch32372
2021AApril42989
2021BApril42390
2021AMay52989
2021BMay52390
2021AJune62989
2021BJune62390
2021AJuly72979
2021BJuly72365
2021AAugust83003
2021BAugust82376
2021ASeptember93003
2021BSeptember92376
2021AOctober103003
2021BOctober102424
2021ANovember113003
2021BNovember112424
2021ADecember123003
2021BDecember122424
2022AJanuary13113
2022BJanuary12403
2022AFebruary23113
2022BFebruary22403
2022AMarch33113
2022BMarch32403
2022AApril43109
2022BApril42403
2022AMay53109
2022BMay52403
2022AJune63110
2022BJune62510
2022AJuly73110
2022BJuly72510
2022AAugust83110
2022BAugust82510
2022ASeptember93110
2022BSeptember92510
2022AOctober103215
2022BOctober102376
2022ANovember113290
2022BNovember112382
2022ADecember123292
2022BDecember122382
2023AJanuary13499
2023BJanuary12473
2023AFebruary23362
2023BFebruary22458
2023AMarch33353
2023BMarch32459

 

 

i tried multple formulas but the output was not correct which i need.

 

any help is appreciated

1 ACCEPTED SOLUTION

here is the file for your reference

View solution in original post

4 REPLIES 4
wdx223_Daniel
Super User
Super User

Rolling Avg Last 12 months =
VAR _tbl =
    TOPN (
        12,
        WINDOW (
            -11,
            REL,
            0,
            REL,
            ALL ( Data[Reporting Period], Data[Month_number] ),
            ORDERBY ( Data[Reporting Period], ASC, Data[Month_number], ASC )
        ),
        data[reporting period],,
        data[month_number],
    )
RETURN
    IF (
        MAX ( Data[Reporting Period] ) > 2021,
        AVERAGEX (
            _tbl,
            CALCULATE ( SUM ( Data[ Result] ), ALLSELECTED ( Data[Month] ) )
        )
    )
Rolling Avg Last 12 months YTD =
VAR _tbl =
    WINDOW (
        -11,
        REL,
        0,
        REL,
        ALL ( Data[Reporting Period], Data[Month_number] ),
        ORDERBY ( Data[Reporting Period], ASC, Data[Month_number], ASC ),
        ,
        PARTITIONBY ( Data[Reporting Period] )
    )
RETURN
    AVERAGEX (
        _tbl,
        CALCULATE ( SUM ( Data[ Result] ), ALLSELECTED ( Data[Month] ) )
    )

wdx223_Daniel_0-1682583880419.png

it is not what you really want. but maybe it gives you some tips.

 

Rolling Avg Last 12 months values are correct in the screenshot...thanks for that

but when i tried to use your formula i am little confused after orderby line which seems to be like meausre are used, so am i supposed to create a measure for reporting period and month_number??


is it possible for you to share the pbix file?

     ORDERBY ( Data[Reporting Period], ASC, Data[Month_number], ASC )
        ),
        data[reporting period],,
        data[month_number],

 

i will brainstorm wrt YTD more. as the output for BU A, for year 2021 are 246-Jan, 495-Feb, 744-March and so on ... will search more about that 

here is the file for your reference

Thankyou for the rolling average formula..It helped

for YTD cumulative i used below formula

 

Cumulative = 
CALCULATE (
    SUM('Table'[Result]),
    FILTER ( ALL ( 'Table'[Month_number] ), 'Table[Month_number] <= MAX ( 'Table'[Month_number] ) )
)/12



https://community.powerbi.com/t5/DAX-Commands-and-Tips/Sum-previous-months-result-to-next-month-for-...

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