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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jt1024
Helper II
Helper II

% of categorized data when not all data has a category that is not % Grand Total of count of categor

Hello,

 

Usual apologies for this question if it's easy. I am a relatively new user who uses Power BI desktop infrequently, sadly.

 

I think this question will have an easy answer, for those good with measures and filter contexts, or maybe it's even easier than that.

 

I've been fighting it for a couple of hours, I think my problem is I don't fully appreciate the filter context (I haven't completed enough SQBI.com courses, those guys are the best!) and I'm not properly grasping how to tell Power BI what I want to calculate in a DAX measure.  I know enough to know the difference between M query language data extraction and initial processing, and I've done work with a number of measures but I'm still by no means proficient with measures.

 

Here is my problem in simplified form:

 

If I have data like this:

RecordCategory
1Apples
2Apples
3Pears
4Bolts
5 
6Apples
7 

We can see that Apples occurs 3 out of 7 times or about 42% of the time.

Of the data with categories, Apples occurs 3 out of 5 times or about 60% of the time.

 

Now let's say the table has 1000's of records where not all have categories, and the # of categories is say 50 different categories.

 

When using a filter or a slicer I want to show the % of data in a given category out of all data that has categories.

Or put another way I don't want the effect of the 'Show as % of grand total' where as soon as you slice the data by any number of categories the %'s change to be %'s that sum to 100%

 

So imagine there's 10,000 records.  8000 have categories.  5000 are categorized as Apples, and 1000 are categorized as Pears.  So the % of categorized data that is apples is 62.5%, and for pears it is 12.5%.  How do I show that in a matrix or table and -ONLY- show the category Apples (or any combination of categories the user would like to select) like this:

Category% of categorized data
Apples62.5%
Pears12.5%

 

Does that make sense as a problem?

 

Thanks again to this wonderful community for taking the time to read my question and for any who provide some possible solutions.

 

- Jim

1 ACCEPTED SOLUTION

Hi @jt1024 ,

 

Here I create a sample to have a test.

RicoZhou_0-1654593354695.png

Measure:

Measure = 
VAR _COUNT_EACH_CATEGORY = CALCULATE(COUNT('Table'[Category]),ALLEXCEPT('Table','Table'[Category]))
VAR _TOTAL = CALCULATE(COUNT('Table'[Category]),FILTER( ALL('Table'),'Table'[Category]<>BLANK()))
RETURN
DIVIDE(_COUNT_EACH_CATEGORY,_TOTAL)

Remove Blank in [Category] column on page level/visual level filter. Result is as below.

RicoZhou_1-1654593443996.png

 

 

Best Regards,
Rico Zhou

 

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

View solution in original post

4 REPLIES 4
danextian
Super User
Super User

hi @jt1024 ,

Please try this:

% of Category =
DIVIDE (
    SUM ( 'Table'[Record] ),
    CALCULATE ( SUM ( 'Table'[Record] ), ALL ( 'Table'[Category] ) )
)

You should be getting the result below

danextian_0-1654213046954.png

danextian_1-1654213092527.png

 

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hello danextian,

When I create a test PBIX file with the data I described:

jt1024_0-1654298745367.png

And then in the desktop create this measure:

jt1024_1-1654298792022.png

When I try to place that measure in a visual it's not working, I think because we're trying to SUM over text data not numbers?

jt1024_2-1654298906679.png

jt1024_3-1654299148672.png

Again thanks so much for looking at my problem and assisting me.

Very large apologies if there was an implicit step I've missed. I have not had my head in Power BI for a few months.

- Jim

Hi @jt1024 ,

 

Here I create a sample to have a test.

RicoZhou_0-1654593354695.png

Measure:

Measure = 
VAR _COUNT_EACH_CATEGORY = CALCULATE(COUNT('Table'[Category]),ALLEXCEPT('Table','Table'[Category]))
VAR _TOTAL = CALCULATE(COUNT('Table'[Category]),FILTER( ALL('Table'),'Table'[Category]<>BLANK()))
RETURN
DIVIDE(_COUNT_EACH_CATEGORY,_TOTAL)

Remove Blank in [Category] column on page level/visual level filter. Result is as below.

RicoZhou_1-1654593443996.png

 

 

Best Regards,
Rico Zhou

 

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

Brilliant!  That works perfectly!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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