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
NATO-OZ
Frequent Visitor

Average of multiple columns with null values in Power BI

Hi all,

 

First post!

 

In Power BI I'm trying to 'Add a column' that is the average of 3 columns, one of the columns may have a 'null' value in it, please see the data below:

 

So for each row I need to find the average of '47254', '121844' and '139820', unfortunately data is not always present and will have a 'null' as shown and this needs to be excluded.

 

PowerBI.JPG  

 

Thank you in advance

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

I agree that unpivotting is almost always the way to go.  However, if you need to keep your 3 columns pivotted, this approach will get you the average and exclude nulls

 

Custom Column M code - List.Average(List.RemoveNulls({[Column2],[Column3],[Column4]}))

 

Putting your 3 columns as a list inside curly brackets makes it a list, and then you can take advantage of the set of list functions in M.

 

If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
mahoneypat
Employee
Employee

I agree that unpivotting is almost always the way to go.  However, if you need to keep your 3 columns pivotted, this approach will get you the average and exclude nulls

 

Custom Column M code - List.Average(List.RemoveNulls({[Column2],[Column3],[Column4]}))

 

Putting your 3 columns as a list inside curly brackets makes it a list, and then you can take advantage of the set of list functions in M.

 

If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thank you this is perfect, as part of the next step I unpivot the columns but wanted a site average before I did that and appended all my sites together

Greg_Deckler
Super User
Super User

@NATO-OZ - Welcome to the community! You might think about unpivoting those columns in Power Query and then you could just use the default average aggregation or AVERAGE DAX function. If you cannot unpivot the columns, you can use my MC Aggregation DAX Quick Measure here: https://community.powerbi.com/t5/Quick-Measures-Gallery/Multi-Column-Aggregations-MC-Aggregations/m-...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.