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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
andrehawari
Helper II
Helper II

Calculate Moving Average Last 6 Month with not sequencial Date with Category

hi I have similar problem like this

http://community.powerbi.com/t5/Desktop/Calculate-Moving-Average-Last-6-Month-with-not-sequencial-Da....

I need to create measure that calculate moving average for the last 6 months, but the date is not always sequencial 

 

 

But the structure table is more complex, because it includes category and sub category. The current solution does not give the abiity to slice by those 2 columns

MonthHas SalesCategorySubCategoryValue
17-JanYesAa110
17-FebYesAa111
17-MarNoAa112
17-AprNoAa113
17-MayYesAa114
17-JunYesAa115
17-JulYesAa116
17-AugNoAa117
17-SepYesAa118
17-OctYesAa119
17-NovYesAa120
17-DecYesAa121
18-JanYesAa122
18-FebNoAa123
18-MarYesAa124
18-AprNoAa125
18-MayYesAa126
18-JunYesAa127
17-JanYesAa210
17-FebYesAa211
17-MarNoAa212
17-AprNoAa213
17-MayYesAa214
17-JunYesAa215
17-JulYesAa216
17-AugNoAa217
17-SepYesAa218
17-OctYesAa219
17-NovYesAa220
17-DecYesAa221
18-JanYesAa222
18-FebNoAa223
18-MarYesAa224
18-AprNoAa225
18-MayYesAa226
18-JunYesAa227
17-JanYesBb110
17-FebYesBb111
17-MarNoBb112
17-AprNoBb113
17-MayYesBb114
17-JunYesBb115
17-JulYesBb116
17-AugNoBb117
17-SepYesBb118
17-OctYesBb119
17-NovYesBb120
17-DecYesBb121
18-JanYesBb122
18-FebNoBb123
18-MarYesBb124
18-AprNoBb125
18-MayYesBb126
18-JunYesBb127

 

Any idea would be really appreaciated

Thanks!

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @andrehawari

Try this measure

Measure = 
VAR mydate =
SELECTEDVALUE ( Sheet1[Month] )
VAR cate=SELECTEDVALUE(Sheet1[Category])
VAR subcate=SELECTEDVALUE(Sheet1[SubCategory])
VAR Previous6 =
TOPN (
6,
FILTER ( ALL ( Sheet1 ), Sheet1[Month] < mydate && Sheet1[Has Sales] = "Yes"&&[Category]=cate&&[SubCategory]=subcate ),
[Month], DESC
)
RETURN
AVERAGEX ( Previous6, [Value] )

1.png

2.png

 

 

Best Regards

Maggie

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

 

What result are you expecting?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-juanli-msft
Community Support
Community Support

Hi @andrehawari

Try this measure

Measure = 
VAR mydate =
SELECTEDVALUE ( Sheet1[Month] )
VAR cate=SELECTEDVALUE(Sheet1[Category])
VAR subcate=SELECTEDVALUE(Sheet1[SubCategory])
VAR Previous6 =
TOPN (
6,
FILTER ( ALL ( Sheet1 ), Sheet1[Month] < mydate && Sheet1[Has Sales] = "Yes"&&[Category]=cate&&[SubCategory]=subcate ),
[Month], DESC
)
RETURN
AVERAGEX ( Previous6, [Value] )

1.png

2.png

 

 

Best Regards

Maggie

Hi Maggies,

 

thanks a lot ! It works now, however, I was wondering, since my data will have have millions of row in azure analysis service database, will it affect performance badly using the averagex function? 

 

thanks

Hi @andrehawari

Have you use the formula as a test?

Does it perform well?

If not, please tell me, I may change other formula which could perform better.

 

Best Regards

Maggie

The system perform well on the sample data,  I will get back to you once the system is live in production because it will contains million of rows after that

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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