Forum Discussion
Average excepts only column reference
- 1 year ago
Hi klehar ,
The error in your DAX formula occurs because the AVERAGE function only accepts a column reference as an argument, but you are passing an expression (1 - DIVIDE(netprice, listprice)).
Solution:
Instead of using AVERAGE, use the AVERAGEX function, which allows row-wise calculations on a table.Corrected Code:
DAXRETURN IF( listprice <> 0, AVERAGEX( TableName, 1 - DIVIDE(TableName[netprice], TableName[listprice]) ), BLANK() )
AVERAGEX iterates over the TableName and computes the expression for each row before averaging the results.TableName should be replaced with your actual table name containing netprice and listprice.
Please mark this post as solution if it helps you. Appreciate Kudos.
Hi klehar ,
The error in your DAX formula occurs because the AVERAGE function only accepts a column reference as an argument, but you are passing an expression (1 - DIVIDE(netprice, listprice)).
Solution:
Instead of using AVERAGE, use the AVERAGEX function, which allows row-wise calculations on a table.
Corrected Code:
DAX
RETURN
IF(
listprice <> 0,
AVERAGEX(
TableName,
1 - DIVIDE(TableName[netprice], TableName[listprice])
),
BLANK()
)
AVERAGEX iterates over the TableName and computes the expression for each row before averaging the results.
TableName should be replaced with your actual table name containing netprice and listprice.
Please mark this post as solution if it helps you. Appreciate Kudos.
Thanks for the reply
What about percentile.inc?