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
rachaelwalker
Resolver III
Resolver III

Rolling 12 month for sum qty

I would like to verify that I am using the right calculation to create a Rolling 12 month average on QTY. My data set is below and formula. I want to use this to create a line value on a bar chart similar to below

 

This is the formula I found searching google

 

R12M Sell_Quote_Qty = 
CALCULATE(
	SUM('Sell Quotes'[Quantity]), 
	DATESINPERIOD('Sell Quotes'[Opp Close Date], LASTDATE('Sell Quotes'[Opp Close Date]), -12, Month)
)
/
CALCULATE(
	DISTINCTCOUNT('Sell Quotes'[Opp Close Date]),
	DATESINPERIOD('Sell Quotes'[Opp Close Date], LASTDATE('Sell Quotes'[Opp Close Date]), -12, MONTH)
)

 

Opp Close DateQuantity
1/7/20212
2/24/20212
3/15/202123
3/25/20211
3/26/20214
3/30/20215
3/31/202113
4/8/202125
4/13/202119
4/14/2021114
4/23/202124
4/26/2021333
4/27/202130
4/28/202132
4/29/202168
4/30/2021225
5/12/2021649
5/20/2021340
5/21/2021114
5/24/20217
5/26/202146
5/27/202196
6/2/202155
6/3/202111
6/4/20219
6/8/20211
6/9/20219
6/10/202133
6/15/202116
6/17/202125
6/23/202110
6/24/2021287
6/29/2021602
7/6/2021233
7/8/2021107
7/9/20217
7/13/202116
7/14/2021119
7/16/202114
7/19/202110
7/21/202147
7/26/2021212
7/27/202145
7/28/2021159
7/29/202182
7/30/202142
8/2/202183
8/3/2021111
8/5/2021884
8/6/2021147
8/10/202129
8/11/202113
8/12/20214
8/16/20211
8/17/202158
8/18/2021422
8/19/202126
8/20/20214
8/24/202120
8/25/202120
8/26/20216
8/27/202118
8/31/202187
9/1/202144
9/3/202127
9/8/2021606
9/9/20217
9/10/2021298
9/13/2021539
9/14/20216
9/15/202176
9/17/202194
9/22/202119
9/23/2021688
9/27/20211013
9/28/202123
9/29/2021525
9/30/202152
10/1/20214
10/5/2021685
10/6/202138
10/8/202114
10/12/2021345
10/13/2021117
10/14/202177
10/15/2021265
10/18/2021111
10/19/202135
10/20/2021361
10/21/20216
10/22/20213024
10/25/2021407
10/26/2021201
10/27/2021256
10/28/20211664
10/29/2021113
10/31/2021191
11/1/2021109
11/2/202182
11/3/2021234
11/9/202175
11/10/2021128
11/11/20212717
11/12/20218
11/16/2021331
11/18/202196
11/22/2021148
11/23/2021305
11/24/202125
11/30/2021190
12/1/202142
12/2/202177
12/3/2021876
12/8/2021167
12/9/2021151
12/10/2021163
12/11/202128
12/13/2021180
12/15/2021141
12/16/202156
12/22/202121
12/24/2021227
12/29/20218
12/30/2021252
12/31/20216172
1/1/202227
1/3/202266
1/9/202247
1/10/202253
1/12/202251
1/16/2022303
1/28/202283
1/30/202228
1/31/2022400
2/1/202239
2/3/202235
2/10/202215
2/12/202245
2/28/2022297
3/1/20224
3/10/20225
6/30/202211

rachaelwalker_0-1639692921668.png

 

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

It is for creating Monthly-Quantity of 12month rolling average.

 

Picture1.png

 

QTY total 12month rolling avg: =
VAR lastdateqty =
CALCULATE ( MAX ( 'Sell Quotes'[Opp Close Date] ), REMOVEFILTERS () )
VAR currentyearmonthsort =
MAX ( Dates[YearMonth Sort] )
VAR yearmonthtable =
SUMMARIZE (
FILTER (
ALL ( Dates ),
Dates[YearMonth Sort] <= currentyearmonthsort
&& Dates[YearMonth Sort] >= currentyearmonthsort - 11
),
Dates[Year & Month],
Dates[YearMonth Sort]
)
VAR addqty =
ADDCOLUMNS ( yearmonthtable, "@monthlyqty", [QTY Total:] )
RETURN
IF ( MIN ( Dates[Date] ) <= lastdateqty, AVERAGEX ( addqty, [@monthlyqty] ) )

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

6 REPLIES 6
Anonymous
Not applicable

HI @rachaelwalker,

Here is the measure expression of the rolling 12 month average of 'Quantity' field, you can try if it helps:

R12M Sell_Quote_Qty =
VAR currDate =
    MAX ( 'Sell Quotes'[Opp Close Date] )
RETURN
    CALCULATE (
        AVERAGE ( 'Sell Quotes'[Quantity] ),
        FILTER (
            ALLSELECTED ( 'Sell Quotes' ),
            YEAR ( [Opp Close Date] )
                >= DATE ( YEAR ( currDate ), MONTH ( currDate ) - 12, DAY ( currDate ) )
                && [Opp Close Date] <= currDate
        )
    )

Regards,

Xiaoxin Sheng

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

It is for creating Monthly-Quantity of 12month rolling average.

 

Picture1.png

 

QTY total 12month rolling avg: =
VAR lastdateqty =
CALCULATE ( MAX ( 'Sell Quotes'[Opp Close Date] ), REMOVEFILTERS () )
VAR currentyearmonthsort =
MAX ( Dates[YearMonth Sort] )
VAR yearmonthtable =
SUMMARIZE (
FILTER (
ALL ( Dates ),
Dates[YearMonth Sort] <= currentyearmonthsort
&& Dates[YearMonth Sort] >= currentyearmonthsort - 11
),
Dates[Year & Month],
Dates[YearMonth Sort]
)
VAR addqty =
ADDCOLUMNS ( yearmonthtable, "@monthlyqty", [QTY Total:] )
RETURN
IF ( MIN ( Dates[Date] ) <= lastdateqty, AVERAGEX ( addqty, [@monthlyqty] ) )

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.

@Jihwan_Kim  Thank you for taking the time to help me. This is very helpful. I am now using my date table and your measure but it is returning an error "Parameter is not correct type"

rachaelwalker_0-1639757018438.png

 

Additional information that may or may not be relevant:

1. My date table is not marked as a date table. Should I mark it as date table?

2. My date table is created in power query using a function. My date table did not have YearMonth and YearMonthSort so I created them using DAX.

 

I found if I use ( 'Calendar' ) on line 9, there are no more errors but it is returning the same values as qty. I have tried all the formulas in this thread and same result. My 'Sell Quote'[Opp Close Date] is a lookup column from another table. Would that impact this?

Your formula worked once I corrected my date table and used the date field from date table. Thank you for taking the time

CNENFRNL
Community Champion
Community Champion

R12M =
CALCULATE(
    SUM( 'Sell Quotes'[Quantity] )
        / DISTINCTCOUNT( 'Sell Quotes'[Opp Close Date] ),
    DATESINPERIOD(
        'Sell Quotes'[Opp Close Date],
        MAX( 'Sell Quotes'[Opp Close Date] ),
        -12,
        MONTH
    )
)

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

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.

Top Solution Authors
Top Kudoed Authors