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
SimonNagy
Frequent Visitor

Calculating percentage inside categories

Hello all,

 

I am having a bit of trouble with calculating percentage values from categories, in which data can be one of two values. After spending a good amount of time with this I can't really phrase this question right, so I would give you an example.

 

My data looks similar to this:

... | Category | Status | ...

... | 1 | Passed | ...

... | 1 | Breached | ...

... | 2 | Passed | ...

... | 2 | Passed | ...

and so on.

 

There are four categories in total (1-2-3-4), and three separate columns for three "statuses". 

I've tried with making another table, where status occurancies are summarized by category (i.e., how many have passed in 1st). 

 

I would need to calculate and display how many % of all rows are passed in each category. How would you approach this problem?

 

Thanks in advance,

Simon

2 ACCEPTED SOLUTIONS

Sorry @SimonNagy 

In the all, it should be: 

% total= DIVIDE(
    [Total status],
    CALCULATE([Total status],ALL(MyTable[Status])))

 

View solution in original post

v-tangjie-msft
Community Support
Community Support

Hi @SimonNagy ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a measure. 

% Measure = 
var _a=COUNTROWS(FILTER(ALL('Table'),'Table'[Category]=MAX('Table'[Category]) && 'Table'[Status]="Passed"))
var _b=COUNTROWS(FILTER(ALL('Table'),'Table'[Category]=MAX('Table'[Category]) ))
return DIVIDE(_a,_b)

(3)If you want a table, you can create the table.

Table 2 = SUMMARIZE('Table','Table'[Category],"%",[% Measure])

(4) Then the result is as follows.

vtangjiemsft_0-1696577360487.pngvtangjiemsft_1-1696577374006.png

 

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

5 REPLIES 5
SimonNagy
Frequent Visitor

Hi @v-tangjie-msft and @mlsx4 !

Thank you for your inputs/answers, I've managed to figure it out! As my data is a bit more complex, I've needed to incorporate more steps, but generally using measures were the anwser. Earlies I've complicated things by using dax studio, and making tables from categorizations 😄

Best regards,

Simon

v-tangjie-msft
Community Support
Community Support

Hi @SimonNagy ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a measure. 

% Measure = 
var _a=COUNTROWS(FILTER(ALL('Table'),'Table'[Category]=MAX('Table'[Category]) && 'Table'[Status]="Passed"))
var _b=COUNTROWS(FILTER(ALL('Table'),'Table'[Category]=MAX('Table'[Category]) ))
return DIVIDE(_a,_b)

(3)If you want a table, you can create the table.

Table 2 = SUMMARIZE('Table','Table'[Category],"%",[% Measure])

(4) Then the result is as follows.

vtangjiemsft_0-1696577360487.pngvtangjiemsft_1-1696577374006.png

 

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

mlsx4
Super User
Super User

Hi @SimonNagy 

 

Something like this should work:

 

Total status = COUNTROWS(MyTable)
% total= DIVIDE(
    [Total status],
    CALCULATE([Total status],ALL(MyTable[Category])))

 

 

Hi @mlsx4 ,

thank you for your answer!

I've made the measure, you wrote, and it returned back the distribution of the categories in the table (e.g., .07 of rows are in the 1st category). I think you've put me on the right tracks, though I would need to calculate how many rows are passed in each category.

Cheers,

Simon

Sorry @SimonNagy 

In the all, it should be: 

% total= DIVIDE(
    [Total status],
    CALCULATE([Total status],ALL(MyTable[Status])))

 

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.