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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Do5779
Helper II
Helper II

subquery SQL in Power BI - advanced editor

Hi, I have the following problem with SQL in Power BI advanced editor. 
This ist my SQL code and I want to select every product with the highest average price. 

The productnumber is the product-ID for the identification, "Quantity" is the quantity of the product and "QuantityPrice" the total amount of the buy. 

Everything works fine apart from the subquery. Is I want to execute this part I get the following message:

 

Microsoft SQL: Divide by zero error encountered. 

 

But there is no Divide by zero in the wohle calculation. Does anyone have an idea😐?

 

   With Test1 as
    (Select 
T1.productnumber as productnumber ,
        T1.Quantity,
        T1.QuantityPrice as QuantityPrice
   T1.Quantity/ T1.QuantityPrice as Price_per_product

from Table1 T1)

Select *, max(Price_per_product) over Test1.productnumber 

where Price_per_product = (select ax(Price_per_product) over Test1.productnumber from Test1)

 

 

 

 

2 REPLIES 2
BA_Pete
Super User
Super User

Hi @Do5779 ,

 

It's not this, is it?

 

BA_Pete_0-1662123956496.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




hi @BA_Pete thank you, but it was a typing error of me for this post. I should be "max(..."

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.