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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
l6903b5
Frequent Visitor

Rolling average per category with date table

Hi, 

 

I have a simple PM dataset containing product category, date and score (1-10). 

ProductDate (YYY-MM-DD)ITV Score
BS2023-01-279.0
PS2023-01-208.2
LP2023-01-197.0
VO2023-01-177.5
PN2023-01-257.8
etc  

Products belong to product group B2B or Retail. 

 

I have a date table based on the PM dates: zzCalendar = CALENDAR(MIN(PM[DATE]);MAX(PM[DATE])).

I have a measurement 

ITV rolling avg =

var _ITV = AVERAGEX(values(zzProduct[PRODUCT]); CALCULATE([ITV];DATESINPERIOD(zzCalendar[Date];max(zzCalendar[Date]);-365;DAY)))
return
if (HASONEVALUE(zzProduct[PRODUCT]);_ITV; AVERAGEX(values(zzProduct[PRODUCT]); ROUND(_ITV;2)))
 
The measurement calculates the average score for each product and for each aggregation (Product group and Total) it calculates the average of the products (rounded on 2 decimals). 
 
Problem with this measurement is that max(zzCalendar[Date]) or lastdate(zzCalendar[Date]) returns the lastdate for all product categories. But the product categories have different lastdates. For each product category the daterange  for the calculation is different. 
 
So I tried a different approach:

ITV rolling avg =

var _ITV = AVERAGEX(values(zzProduct[PRODUCT]); CALCULATE([ITV];DATESINPERIOD(zzCalendar[Date];max(PM[Date]);-365;DAY)))
return
if (HASONEVALUE(zzProduct[PRODUCT]);_ITV; AVERAGEx(values(zzProduct[PRODUCT]); ROUND(_ITV;2)))
 
This formula returns the rights rolling averages, but when I put the rolling average in a line chart to see the trend it gives unwanted results. The rolling average drops sharply and the number of measurements drops from around 400 to 9.  It has got to do with the fact that in december last year there were no measurements for B2B.
Trend.PNG

 If I know how I would have inserted a dataset and a pbix, but I hope somebody can help?

0 REPLIES 0

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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