Subcategory as % of category

Solution 1:

Try using the following measure:

% of Part = 
VAR __a = IF( ISBLANK( [Code qty]), BLANK(), CALCULATE([Code qty], ALLSELECTED(Codes_lookup[Code]) ) )
VAR __b = [Code qty]
    
VAR div = DIVIDE(__b, __a, 0 )
Return div

I got the expected result:

enter image description here