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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Nayababbasi91
Frequent Visitor

How to calculate sub-product quantity

Hi 

 

I would like to know how to calculate the quantity of sub-products using the table provided.

 

Nayababbasi91_0-1731421569774.png

Once I have the sub-product total Qty, I can create a measure to calculate % by Sub-product. 

 

Please advise. 

1 ACCEPTED SOLUTION
DataNinja777
Super User
Super User

Hi @Nayababbasi91 ,

 

You can produce your required output by writing dax measures like below:

Sub-product (all) = calculate(sum('Table'[Brand Qty]),all('Table'[Sub-product]))

Then use the measure above in another measure to calculate the % share of the total.

Sub-product quantity% = VAR Quantity= sum('Table'[Brand Qty])
return 
divide (Quantity,[Sub-product (all)])

The resulting output looks like below:

DataNinja777_1-1731423252627.png

 

Best regards,

 

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

Write these measures

BQ = sum(Data[Brand Qty])

TBQ = calculate([BQ],all(Data[Product]),all(Data[sub-product]))

Ratio = divide([BQ],[TBQ])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Thanks for the reply from DataNinja777 , please allow me to provide another insight: 
Hi  @Nayababbasi91 ,

 

Here are the steps you can follow:

1. Create measure.

Sub-product Qty =
SUMX(
    FILTER(ALL('Table'),
    'Table'[Product]=MAX('Table'[Product])&&'Table'[Sub-product]=MAX('Table'[Sub-product])),[Brand QTY])
% by Sub-product =
var _sumall=SUMX(ALL('Table'),[Brand QTY])
return
DIVIDE(
    [Sub-product Qty],_sumall)

2. Result:

vyangliumsft_0-1731464316484.png

 

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Nayababbasi91
Frequent Visitor

Thank you so much. 
The only thing which isn't working is the variable:

 

 

Quantity= sum('Table'[Brand Qty])

 

I need to divide the total, which is 70, by each sub-product. 

 

The sum gives the row total, not the grand total. 

 

DataNinja777
Super User
Super User

Hi @Nayababbasi91 ,

 

You can produce your required output by writing dax measures like below:

Sub-product (all) = calculate(sum('Table'[Brand Qty]),all('Table'[Sub-product]))

Then use the measure above in another measure to calculate the % share of the total.

Sub-product quantity% = VAR Quantity= sum('Table'[Brand Qty])
return 
divide (Quantity,[Sub-product (all)])

The resulting output looks like below:

DataNinja777_1-1731423252627.png

 

Best regards,

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Top Solution Authors