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

Easier way to do weighted average

Is there any easier way to calculate weighted average compared to what I am doing right now? The current measure I am using returns the correct answer, but is probably the worst way to calculate it. Thanks for the help!

Avg User per Family =
var one = CALCULATE(SUM(Table[Count]), Table[UserCount] = 1)
var two = CALCULATE(SUM(Table[Count]), Table[UserCount] = 2)
var three = CALCULATE(SUM(Table[Count]), Table[UserCount] = 3)
var four = CALCULATE(SUM(Table[Count]), Table[UserCount] = 4)
var five = CALCULATE(SUM(Table[Count]), Table[UserCount] = 5)
var six = CALCULATE(SUM(Table[Count]), Table[UserCount] = 6)
var seven = CALCULATE(SUM(Table[Count]), Table[UserCount] = 7)
var eight = CALCULATE(SUM(Table[Count]), Table[UserCount] = 😎
var nine = CALCULATE(SUM(Table[Count]), Table[UserCount] = 9)
var ten = CALCULATE(SUM(Table[Count]), Table[UserCount] = 10)
var eleven = CALCULATE(SUM(Table[Count]), Table[UserCount] = 11)
var twelve = CALCULATE(SUM(Table[Count]), Table[UserCount] = 12)
var thirteen = CALCULATE(SUM(Table[Count]), Table[UserCount] = 13)
var fourteen = CALCULATE(SUM(Table[Count]), Table[UserCount] = 14)
var fifteen = CALCULATE(SUM(Table[Count]), Table[UserCount] = 15)
var sixteen = CALCULATE(SUM(Table[Count]), Table[UserCount] = 16)
var seventeen = CALCULATE(SUM(Table[Count]), Table[UserCount] = 17)
var eighteen = CALCULATE(SUM(Table[Count]), Table[UserCount] = 18)
var nineteen = CALCULATE(SUM(Table[Count]), Table[UserCount] = 19)
var total = SUM(Table[Count])
return
DIVIDE(
    one+2*two+3*three+4*four+5*five+6*six+7*seven+8*eight+9*nine+10*ten+11*eleven+12*twelve+13*thirteen+14*fourteen+15*fifteen+16*sixteen+17*seventeen+18*eighteen+19*nineteen,
    total
    )

Sample Data
CountUserCount
785318590
8155801
945992
161213
38594
17305
4506
2067
1518
839
4710
3211
2812
1813
1214
1015
816
1417
1418
3119
1 ACCEPTED SOLUTION
alexei7
Continued Contributor
Continued Contributor

Thanks!

 

Try this:

 

Avg User per Family = DIVIDE(SUMX('Table','Table'[Count]*'Table'[UserCount]),sum('Table'[Count])) 

 

Hope that helps,

Alex

View solution in original post

4 REPLIES 4
alexei7
Continued Contributor
Continued Contributor

Hi @Ski900,

 

Yeah, I'm pretty sure there's an easier way of doing it..

Would you be able to post a small sample of your data expected result? That'd make it easier to help

 

Thanks

Alex

Data added!

alexei7
Continued Contributor
Continued Contributor

Thanks!

 

Try this:

 

Avg User per Family = DIVIDE(SUMX('Table','Table'[Count]*'Table'[UserCount]),sum('Table'[Count])) 

 

Hope that helps,

Alex

Works perfectly. Thanks for the help 🙂

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.