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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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