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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
pnem
Frequent Visitor

Subcategory as % of category power bi

Hello, 

I would like to calculate saldo subcategory as  share in category.

Here is an example of data and what results I want to get. 

pnem_0-1669198169311.png


Green column is what I expect as a result, Red column is what I get from dax formula



Treid something like this : 

 

%ofSubCat =
DIVIDE(
CALCULATE(sum([Saldo]),
ALLEXCEPT(Ftable,[SubCat])),
CALCULATE(sum([Saldo]),ALLEXCEPT(dimCat,dimCat[Category])))



but this is showing me uncorrect data. 

1 ACCEPTED SOLUTION
OdetaJ
Frequent Visitor

% of SubCat = 
VAR SubcatCount = DISTINCTCOUNT(Categories[Subcategory])
RETURN
    IF( NOT ISINSCOPE(Categories[Subcategory]) && ISINSCOPE(Categories[Category]),
        DIVIDE( SUM('Fact'[Saldo]), SubcatCount )
    )
 
OdetaJ_0-1669223124849.png

Also, the formula can change if you use filters and/or slicers.

View solution in original post

4 REPLIES 4
daXtreme
Solution Sage
Solution Sage

daXtreme_0-1669206143341.png

%ofSubCat = 
var VisibleCategories = DISTINCT( T[Category] )
return
if(
    and(
        NOT ISINSCOPE( T[Subcategory] ),
        ISINSCOPE( T[Category] )
    ),
    SUMX(
        VisibleCategories,
        CALCULATE(
        
            var SubcategoriesVisible = 
                DISTINCT( T[Subcategory] )
            var SubcategoriesVisibleCount =
                COUNTROWS( SubcategoriesVisible )
            var SubcategoriesVisibleWithSaldoCount =
                COUNTROWS(
                    FILTER(
                        SubcategoriesVisible,
                        [Total Saldo] = 1
                    )
                )
            var Result =
                DIVIDE(
                    SubcategoriesVisibleWithSaldoCount,
                    SubcategoriesVisibleCount
                )
            return
                Result,
                
            ALLSELECTED( T[Subcategory] )
        )
    )
)
OdetaJ
Frequent Visitor

Hi @pnem,

 

Could you please tell me how you want to calculate the "%ofSub"? Do you only count the times "Saldo" is some value for the subcategory? This is why for Category 1:

%ofSub = number of times Saldo = 1 divided by number of subcategories in a Category 1  = 2/3,

or do you want to sum up "Saldo" and divide it by the number of subcategories in a specific category? In your example, the result is the same, but if you have other "Saldo" values than 1, you will get a different result and need to use a different formula.

pnem
Frequent Visitor

Hello @OdetaJ I am having only value 1 for Saldo, and goal is to devide number of Saldo's with one with number of subcategories in each category.
Hope you understand the idea, thanks!

OdetaJ
Frequent Visitor

% of SubCat = 
VAR SubcatCount = DISTINCTCOUNT(Categories[Subcategory])
RETURN
    IF( NOT ISINSCOPE(Categories[Subcategory]) && ISINSCOPE(Categories[Category]),
        DIVIDE( SUM('Fact'[Saldo]), SubcatCount )
    )
 
OdetaJ_0-1669223124849.png

Also, the formula can change if you use filters and/or slicers.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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