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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
SandraJ
New Member

Power Query - Add an Average Column from other columns in the table excluding zeros from Avg Calc

I'm new to Power Query and need help with adding an average column that would average a few columns in the table but exclude column with values of zero from the average calcuation. 

 

For example:

 

Column 1         Column 2        Avg Column

  5                       0                     5

 

How to I modify the M code below so that it exclude zeros from average calculation:

= Table.AddColumn(#"Renamed Columns1", "Average", each List.Average({[#"Column 1"], [Column 2]}), type number)

2 ACCEPTED SOLUTIONS
Jakinta
Solution Sage
Solution Sage

You can try this

 

 

= Table.AddColumn(#"YourTable", "Custom", each List.Average(List.RemoveMatchingItems({[Column1],[Column2],[Column3]},{0})), type number)

or

 

= Table.AddColumn(#"YourTable", "Custom", each List.Average(List.Select({[Column1],[Column2],[Column3]},each _<>0)), type number)

 

View solution in original post

The easiest way is to replace null with 0 in next step.

View solution in original post

3 REPLIES 3
Jakinta
Solution Sage
Solution Sage

You can try this

 

 

= Table.AddColumn(#"YourTable", "Custom", each List.Average(List.RemoveMatchingItems({[Column1],[Column2],[Column3]},{0})), type number)

or

 

= Table.AddColumn(#"YourTable", "Custom", each List.Average(List.Select({[Column1],[Column2],[Column3]},each _<>0)), type number)

 

Thank you so much Jakinta. The solution worked perfectly. Much appreciated.  On more question, if the Avg Column result is "null" because both Column 1 & 2 have zero value, how to I modify the M code so that the Avg Column value is the number "0" instead of the word "null"? Example below:

SandraJ_0-1620791591665.png

 

The easiest way is to replace null with 0 in next step.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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