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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Gilad
Frequent Visitor

wrong result when applying divide with blank value in details

Hello Community , 

I am trying to create an average price by dividing sales amount by quantity.

I have filter records in the amount variable so calculation will apply only on records that the amount is greater than 1 

The same calculation is apply on qty that should be greater than 0 

It seems that aggregate divide result is incorrect as some of calculation result in detail are equal to blank.

I know I need to filter out blank but I did not succeed to get correct result.

please advice.

 

avg_price =
var vprice = CALCULATE(
SUM(INVOICES[Amount]),
CALCULATETABLE(
VALUES('INVOICES'),
'INVOICES'[Amount] > 1
))
var vqty = CALCULATE(
SUM(INVOICES[qty]),
CALCULATETABLE(
VALUES('INVOICES'),
'INVOICES'[qty] > 0
))
return DIVIDE(vprice , vqty, 0)

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @Gilad 

 

the filters need to be applied for each row of your table simultaneously.

 

Supposing your data is like this:

AmtQty
1-1
100
1002
4003

try to plot a measure like:

 

Avg Price = 
VAR _table = 
FILTER(
    TableName, 
    TableName[Amt]>1&&TableName[Qty]>0
)
VAR _amt = SUMX(_table, TableName[Amt])
VAR _qty = SUMX(_table, TableName[Qty])
RETURN 
DIVIDE(_amt, _qty)

 

it worked like:

FreemanZ_0-1680227970337.png

 

View solution in original post

2 REPLIES 2
GiladO
Regular Visitor

Thank you @FreemanZ  , it works

FreemanZ
Super User
Super User

hi @Gilad 

 

the filters need to be applied for each row of your table simultaneously.

 

Supposing your data is like this:

AmtQty
1-1
100
1002
4003

try to plot a measure like:

 

Avg Price = 
VAR _table = 
FILTER(
    TableName, 
    TableName[Amt]>1&&TableName[Qty]>0
)
VAR _amt = SUMX(_table, TableName[Amt])
VAR _qty = SUMX(_table, TableName[Qty])
RETURN 
DIVIDE(_amt, _qty)

 

it worked like:

FreemanZ_0-1680227970337.png

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.