The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hi
I would like to know how to calculate the quantity of sub-products using the table provided.
Once I have the sub-product total Qty, I can create a measure to calculate % by Sub-product.
Please advise.
Solved! Go to Solution.
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:
Best regards,
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.
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:
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
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.
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:
Best regards,