Forum Discussion
How to calculate average value with null values
- 8 years ago
Hey,
I used this DAX statement to create a "calculated column"
the average = var theTable = UNION( ROW("value",'Table1'[Column1]) ,ROW("value",'Table1'[Column2]) ,ROW("value",'Table1'[Column3]) ,ROW("value",'Table1'[Column4]) ) var theSum = 'Table1'[Column1] + 'Table1'[Column2] + 'Table1'[Column3] + 'Table1'[Column4] var theDivisor = COUNTROWS( FILTER( theTable ,[value] <> BLANK() ) ) return DIVIDE(theSum, theDivisor, BLANK())All the columns have a numeric data tape like decimal.
I create a table from the columns that have to be considered using UNION(ROW(...),...)
I create a simple sum from the values of in the columns that have to be considered
I count the non empty rows in the table.
Based on my sample data this will retrun these results:
Hopefully this is what you are looking for,
Regards,
Tom
Hey,
I used this DAX statement to create a "calculated column"
the average =
var theTable =
UNION(
ROW("value",'Table1'[Column1])
,ROW("value",'Table1'[Column2])
,ROW("value",'Table1'[Column3])
,ROW("value",'Table1'[Column4])
)
var theSum = 'Table1'[Column1] + 'Table1'[Column2] + 'Table1'[Column3] + 'Table1'[Column4]
var theDivisor =
COUNTROWS(
FILTER(
theTable
,[value] <> BLANK()
)
)
return DIVIDE(theSum, theDivisor, BLANK())
All the columns have a numeric data tape like decimal.
I create a table from the columns that have to be considered using UNION(ROW(...),...)
I create a simple sum from the values of in the columns that have to be considered
I count the non empty rows in the table.
Based on my sample data this will retrun these results:
Hopefully this is what you are looking for,
Regards,
Tom
Hello Tom
How can I apply that solution when i have a unique colum, with some nulls values, and I need the average (as a metric) of that unique colum? Thanks