cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

New Member

## Calculating percentage of a subcategory related to total count of the total category (per week)

Hi,

I am looking for some help regarding a bar chart that shows the percentage of the count of a type of subcategory (selected in my filter) based on the total number of a category specified in time. Basically the data I have looks like this:

 Category Week Subcategory A 1 x A 2 y A 2 x A 2 z A 2 y A 2 y A 3 x A 3 z A 3 x B 3 x B 3 y C 1 z

And I want to apply the following filters:

 Filter on Category A Filter on Subcategory x Filter on week [All]

After which I want to show the percentage of counted "x" relative to the total count of "A" per week, i.e. a result (in a bar graph that basically shows:

 Category Subcategory Week % of Category A x 1 100% 2 20% 3 67%

So far, my attempts have not gotten me far (not very experienced yet) and when using metrics to calculate totals and percentages, the Category "A" changes with the filter "x". In other words I keep getting 100% as an outcome in the end. Could someone help me with this?

Thanks a lot!

1 ACCEPTED SOLUTION
Community Champion

@pbv

Try this MEASURE

```% of category =
DIVIDE (
COUNT ( TableName[Subcategory] ),
CALCULATE (
COUNT ( TableName[Subcategory] ),
ALLEXCEPT ( TableName, TableName[Category], TableName[Week ] )
)
)```

Regards
Zubair

Please try my custom visuals
7 REPLIES 7
Frequent Visitor

Hi,

This is good, it is working in matrix table, but not working for bar chart.... here is the scenario:

i have data of around 10k records with consists of name, months, multiple subcategories (poor, good, very good, excellent) in column1

My question is i want to display month wise % of good, poor, very good, excellenet in bar chart.. i wnat to display & on each bar.

Super User

Hi,

Share data in a format that can b pasted in an MS Excel file.  Ensure that there is also a Year column (along with Month column) in your dataset.

Regards,
Ashish Mathur
http://www.ashishmathur.com
Super User

Hi,

Try this measure

=COUNTROWS(Table1)/CALCULATE(COUNTROWS(Table1),ALL(Table1[Subcategory]))

Hope this helps.

Regards,
Ashish Mathur
http://www.ashishmathur.com
New Member

@Ashish_Mathur

Thanks, for my specific question this works as well.

Difference with the solution of @Zubair_Muhammad is that with that solution I can select multiple filters (i.e. a second category related to the above data), while keeping the "base value" the same (i.e. the number of "A"'s). With your solution it is possible to select an additional filter, which than becomes the new "base value".

Community Champion

@pbv

Try this MEASURE

```% of category =
DIVIDE (
COUNT ( TableName[Subcategory] ),
CALCULATE (
COUNT ( TableName[Subcategory] ),
ALLEXCEPT ( TableName, TableName[Category], TableName[Week ] )
)
)```

Regards
Zubair

Please try my custom visuals
Community Champion

@pbv

But i get different results wth your sample data

Regards
Zubair

Please try my custom visuals
New Member

My percentages were atually wrong, I will change it in the original answer, solutions works for me!

Announcements

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

#### Fabric Community Update - July 2024

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

Top Solution Authors
Top Kudoed Authors