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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Stemar_Aubert
Resolver I
Resolver I

Weighted averages in Power Query

Hi,

 

I have a set of data as follow.

LocalStringUnitsValueSum
America2510250
Australia350150
America89201780

 

And so on.

 

Before, I would group and take the average value. But the introduction of Units means I need a variant of Sumproduct() formula.

 

Is there a way, using PowerQuery only, to perform the following operation ?

 

For each America = (250+1780)/(25+89)

 

Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

The code below should do the trick. Just adapt your List.Average to List.Sum([Sum])/List.Sum([Units]).

 

= Table.Group(Source, {"LocalString"}, {{"Sum", each List.Sum([Sum])/List.Sum([Units]), type number}})

 

View solution in original post

3 REPLIES 3
dax
Community Support
Community Support

Hi Sauber,

You could try below M code to see whether it work or not

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsxNLcpMTlTSUTIyBRKGBmCWgVKsDlCutLikKDEnEyRrDMSmIElDmCRco4UlSA9YztwCKBkLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [LocalString = _t, Units = _t, Value = _t, Sum = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"LocalString", type text}, {"Units", Int64.Type}, {"Value", Int64.Type}, {"Sum", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"LocalString"}, {{"total  sum ", each List.Sum([Sum]), type number}, {"total unit", each List.Sum([Units]), type number}, {"all", each _, type table [LocalString=text, Units=number, Value=number, Sum=number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each [#"total  sum "]/[total unit]),
    #"Expanded all" = Table.ExpandTableColumn(#"Added Custom", "all", {"Units", "Value", "Sum"}, {"all.Units", "all.Value", "all.Sum"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded all",{"total  sum ", "total unit"})
in
    #"Removed Columns"

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

The code below should do the trick. Just adapt your List.Average to List.Sum([Sum])/List.Sum([Units]).

 

= Table.Group(Source, {"LocalString"}, {{"Sum", each List.Sum([Sum])/List.Sum([Units]), type number}})

 

@Anonymous Thanks, that worked perfectly !

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors