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
Hayoung
Helper IV
Helper IV

cauculate the percentage by using numerator as top3 percentage and denominator except unsure and no

I would like to calculate the percentage by using numerator as top3 percentage and denominator as percenatge except unsure and no, and then multiply a indicator (1-TOP3[no %]-TOP3[unsure %]). Note that when calcualting the top 3, unsure and no cannot be included. Do anyone know how to modify below DAX?

 

Below is the sample data:( 

Name% of workersAnswer textMerged
A0.102673797UnsureA10
A0.038502674NoA9
A0.131550802A8A8
A0.110160428A7A7
A0.119786096A6A6
A0.275935829A5A5
A0.319786096A4A4
A0.195721925A3A3
A0.263101604A2A2
A0.440641711A1A1
B0.102673797UnsureA10
B0.038502674NoA9
B0.131550802A8A8
B0.110160428A7A7
B0.119786096A6A6
B0.275935829A5A5
B0.319786096A4A4
B0.195721925A3A3
B0.263101604A2A2
B0.440641711A1A1
 
My expected result is 100% stacked bar chart like if filter the Name by A:
48%38%10%4%

 

Top 3 % = DIVIDE(SUMX(TOPN(3,TOP3,TOP3[% of workers],DESC), TOP3[% of workers]),SUM(TOP3[% of workers]))*(1-TOP3[no %]-TOP3[unsure %])
 

Other 3 % = DIVIDE(SUMX(TOPN(3,TOP3,TOP3[% of workers],DESC), TOP3[% of workers]),(SUM(TOP3[% of workers]) - CALCULATE(SUM(TOP3[% of workers]), TOP3[Merged(Q&A)] in {"A9: No","A10: Unsure"})))*(1-CALCULATE(SUM(TOP3[% of workers]), TOP3[Merged(Q&A)] in {"A9: No","A10: Unsure"}))

 

no % = DIVIDE(CALCULATE(SUM(TOP3[% of workers]),TOP3[Answer text]="No"),SUM(TOP3[% of workers]))
unsure % = DIVIDE(CALCULATE(SUM(TOP3[% of workers]),TOP3[Answer text]="Unsure"),SUM(TOP3[% of workers]))
6 REPLIES 6
MFelix
Super User
Super User

Hi @Hayoung ,

 

Believe your issue is on the calculations of the No and Unsure try the following measures:

no % = CALCULATE(SUM(TOP3[% of workers]),TOP3[Answer text]="No")

unsure % = CALCULATE(SUM(TOP3[% of workers]),TOP3[Answer text]="Unsure")

Top 3 % = DIVIDE(
    SUMX(TOPN(3,TOP3,TOP3[% of workers],DESC), TOP3[% of workers]),
    SUM(TOP3[% of workers])-[no %] - [unsure %])
    *(1-TOP3[no %]-TOP3[unsure %])

Other 3 % = 1 - TOP3[no %] - TOP3[unsure %] - TOP3[Top 3 %]

 

 

Since your values are already percentages, making the division will break you values even further.

 

Result:

MFelix_0-1666686752644.png

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Thanks! got it! I would like to ask if you know what is the problem in below case. I would like to create a measure for sum of A14 and A15 after some adjustment, i.e. 0.53/sum(A1:A16)+0.11/(A1:A16). i have tried 

A14+A15 % = DIVIDE(CALCULATE(SUM(TOP5[% of workers]),TOP5[Merged]="A14"||TOP5[Merged]="A15"),SUM(TOP5[% of workers]))

but it seems not correct. It should return 29%, but it return 34%

% of workersMerged
0.254545455A16
0.530481283A15
0.109090909A14
0.054545455A13
0.08342246A12
0.048128342A11
0.021390374A10
0.097326203A9
0.057754011A8
0.021390374A7
0.176470588A6
0.080213904A5
0.037433155A4
0.198930481A3
0.081283422A2
0.376470588A1

Hi @Hayoung ,

 

The calculation seems correct based on the dataset you have provided

 

MFelix_0-1666776773712.png

 

If you make some filters to the Merged column then I can get different results but for all the selection is ok. Do you have any filters based on the Merged column if yes you can wrap you last sum in a ALL statement that will keep the values for the calculation the same:

MFelix_1-1666776869233.png

 

A14+A15 % = DIVIDE(CALCULATE(SUM(TOP5[% of workers]),TOP5[Merged]="A14"||TOP5[Merged]="A15"),CALCULATE(SUM(TOP5[% of workers]), ALL(TOP5[Merged])))

Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Yes, it now return 29%. Probably is because of my dataset actually include both last and current result. And thus, bring a new question. I have tried below for the top 5 % [ sum of top5/(a1:a16)]and i should only take current result and I expect return 50%. However, it give 69% for my result

Q25_Top 5 % = DIVIDE(CALCULATE(SUM(Q25_TOP5[% of workers]),TOPN(5,Q25_TOP5,CALCULATE(SUM(Q25_TOP5[% of workers]),DESC)), Q25_TOP5[% of workers]),CALCULATE(SUM(Q25_TOP5[% of workers]),ALL(Q25_TOP5[Merged])))
MFelix
Super User
Super User

Hi @Hayoung ,

 

If you allow me I believe there is a miss calculation of some sort on your formulas.  When picking up the no % for name A we get the following values:

No % = 0,03850262674 / 1,997860962 =  0.19271925 = 1.93%

 

How are you getting the 10% is this not the sum of the no (0.038502674 - A9) divided by the sum of all the A values?

 

MFelix_0-1666653320087.png

 

Believe that the same tough you apply for this will be applied to the unsure, then  we can check the other formulas.

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



I would like it to be 100% stacked bar chart.  it should be 10% for unsure while 4% for no. 

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.