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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
elenio
Frequent Visitor

calculate averages with null values?

Hi there,

i want to analyze my shops average cart combination.

therefore i have clustered my products in main categories and put them in a matrix. e.g.:

 

image.png

 

in order 1 someone bought 1 x 4kg product and 

in order 2 someone bought 6x Probe. 

 

so far so good.

In the sum line instead of

1 ; 6 ; 7

i would like to see

0,5; 3; 3,5

 

because it is the average bought.

when i create a DAX now:

AVG =  DIVIDE(SUM('Order'[Qty]), DISTINCTCOUNT('Order'[OrderNbr])) 

i get this:
image.png

 

the totals average is fine, but the individual columns not. 

i guess when QTY = null the DISTINCTCOUNT does not work. ...

any idea?

 

thanks

1 ACCEPTED SOLUTION
10 REPLIES 10
AlexisOlson
Super User
Super User

The "averages" you want don't really make sense as averages, IMO. There's only one 4kg order, so the average is simply 1.

 

If you really do want to average over non-existent orders too, then I strongly recommend creating a dimension table for your orders so you don't have to fight against auto-exists. With a dimension table, it becomes much easier to write formulas for combinations that don't necessarily exist in your fact table.

Whitewater100
Solution Sage
Solution Sage

Hi:

Perhaps one alternative:

Avg Amt = IF(NOT(ISFILTERED(Order[Order#])),
DIVIDE(SUM(Order[Qty]), COUNTROWS(ALL(Order))))

this just returns null 😞

elenio_0-1645816002642.png

 

Hello:

Did you look at the file I shared last time?

On Page 1 the results are:

 

Whitewater100_0-1645988595727.png

 

ok. i had a filter on a set of order# to check the solution. if i filter in your example, it also returns nulls. 

Hi Thanks,

still trying to figure out, why it is not working with my data. but yours seems to work fine 😉

 

THANKS!

You can add this measure to the file posted:

Avg Amt Filtered =
DIVIDE(SUM(AvgTable[Qty]), COUNTROWS(ALL(AvgTable)))

ValtteriN
Super User
Super User

Hi,

Try something like this:

Measure 19 =

IF(isblank(SELECTEDVALUE('Table (7)'[Column3])),
divide(sum('Table (7)'[Column2]),COUNTROWS(DISTINCT(all('Table (7)'[Column3]))))
,sum('Table (7)'[Column2]))


ValtteriN_0-1645789255133.png

 


Here I use SELECTEDVALUE to indentify total row and use a separete logic there. For the rest of the rows I simply use the "order value".

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




hi there,

looking at your Column A sum, your solution is not correct:

(100+300)/7 = 57,1 and not 50

 

 

thx

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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