Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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)
Solved! Go to Solution.
hi @Gilad
the filters need to be applied for each row of your table simultaneously.
Supposing your data is like this:
Amt | Qty |
1 | -1 |
10 | 0 |
100 | 2 |
400 | 3 |
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:
hi @Gilad
the filters need to be applied for each row of your table simultaneously.
Supposing your data is like this:
Amt | Qty |
1 | -1 |
10 | 0 |
100 | 2 |
400 | 3 |
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:
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
23 | |
10 | |
10 | |
9 | |
7 |