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

Weighted average with condition

Hi Power BI experts! 

I have a dataset with the last rolling 12 months where I have calculated the Total Weighted Average across all the months I'm looking at. The calculation is quite simple and is working fine.

TotalWeightedAvg = DIVIDE(
    SUMX('Monthly Sales (Product Level)','Monthly Sales (Product Level)'[AdjustedREUnits] * 'Monthly Sales (Product Level)'[YearlyRatio]),
    SUMX('Monthly Sales (Product Level)','Monthly Sales (Product Level)'[AdjustedREUnits]),0)

But I also need one where I get the weighted average per month. How do I add a condition where I look at a column (named MonthRank) where I have ranked the individual months from 1-12, so I get the Weighted Average per Month? There will be multiple rows for each MonthRank.

Thank you in advance! 

Have a nice weekend.

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@nbrandborg , This looks fine for Weighted Avg. For simple Avg you need

 

TotalWeightedAvg = Averagex(Values('Date'[Month Rank),  calculate( DIVIDE(
SUMX('Monthly Sales (Product Level)','Monthly Sales (Product Level)'[AdjustedREUnits] * 'Monthly Sales (Product Level)'[YearlyRatio]),
SUMX('Monthly Sales (Product Level)','Monthly Sales (Product Level)'[AdjustedREUnits]),0))  )

 

 


Rolling avg example

 

Rolling 12 = calculate(AverageX(Values('Date'[MONTH Year]),[MeasurementPct]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-12,MONTH))

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@nbrandborg , This looks fine for Weighted Avg. For simple Avg you need

 

TotalWeightedAvg = Averagex(Values('Date'[Month Rank),  calculate( DIVIDE(
SUMX('Monthly Sales (Product Level)','Monthly Sales (Product Level)'[AdjustedREUnits] * 'Monthly Sales (Product Level)'[YearlyRatio]),
SUMX('Monthly Sales (Product Level)','Monthly Sales (Product Level)'[AdjustedREUnits]),0))  )

 

 


Rolling avg example

 

Rolling 12 = calculate(AverageX(Values('Date'[MONTH Year]),[MeasurementPct]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-12,MONTH))

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.