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
WishAskedSooner
Continued Contributor
Continued Contributor

Dividing and Excluding when No Entries

I have a narrow fact table similar to the following:

WishAskedSooner_1-1717801499778.png

It is joined on the following dimension table:

WishAskedSooner_2-1717801667035.png

My goal is to calculate the average Discount by Quantity, however making sure not to include Quantities for which there is no Discount (or Discount is zero). For example:

 

(10 + 20 + 30) / (40 + 50 + 70) = 60 / 160 = 0.375

 

So, as you can see, since OID 3 does not have a Discount, I need to exclude it from the divisor sum. Alternatively, OID 3 could potentially have an entry for Discount equal to zero in which case I still want to exclude it.

 

Thanks in advance for the help.

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

lbendlin_0-1717805515802.png

Avg Disc By Qty = 
var a = intersect(SELECTCOLUMNS(filter('Table',[AID]=1),[OID]),SELECTCOLUMNS(filter('Table',[AID]=2),[OID]))
return divide(CALCULATE(sum('Table'[VALUE]),'Table'[AID]=1,'Table'[OID] in a),CALCULATE(sum('Table'[VALUE]),'Table'[AID]=2,'Table'[OID] in a),0)

 

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

lbendlin_0-1717805515802.png

Avg Disc By Qty = 
var a = intersect(SELECTCOLUMNS(filter('Table',[AID]=1),[OID]),SELECTCOLUMNS(filter('Table',[AID]=2),[OID]))
return divide(CALCULATE(sum('Table'[VALUE]),'Table'[AID]=1,'Table'[OID] in a),CALCULATE(sum('Table'[VALUE]),'Table'[AID]=2,'Table'[OID] in a),0)

 

@lbendlin Thank you so much for your quick solution! I am not sure why, but division with DAX seems way harder than it should be. Kudos!

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.