Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
This seems a bit silly, but my measures on percentage is showing odd figures. I have a column, with a "Yes" or "No" values. I did the following to extract the number of "Yes" values:
Solved! Go to Solution.
Here you go my friend. Please accept this as correct if this meets your requirements
Edit:
Slightly modified the TotalifYes variable
CountofYesHeard = CALCULATE(COUNTA('Table'[Heardofus?]), 'Table'[Heardofus?] = "Yes")
TotalCounts = VAR choice = SELECTEDVALUE('Table'[Heardofus?]) VAR TotalifYes = [CountofYesHeard], VAR Total = CALCULATE ( COUNTA('Table'[Heardofus?]), all('Table'[Heardofus?]) ) RETURN SWITCH ( choice, "No",BLANK(), "Yes", TotalifYes, Total )
% heard = DIVIDE([CountofYesHeard],[TotalCounts], BLANK())
@Anonymous
Hi, try with this:
CountYes = CALCULATE(COUNTA(Table1[A]),FILTER(Table1,Table1[B]="yes"))
%Yes of Total = DIVIDE([CountYes],CALCULATE(COUNTA(Table1[A]),ALLSELECTED(Table1)))
Regards
Victor
Lima - Peru
Try this.
CountofHeards = COUNTA('Table'[Heardofus?])
TotalCounts = CALCULATE ( [CountofHeards], all('Table'[Heardofus?]) )
% heard = [CountofHeards]/[TotalCounts]
@atif-hafeez this line -
CountofHeards = COUNTA('Table'[Heardofus?])
I am trying to extract all the values that is equals to "yes" nit count all the values. When i did this
Hi @Anonymous
Because of the Merge1[heard of us?] = "Yes" filter, [Yes Measure] always measures the number of "Yes", regardless of the value on the slicer. On the denominator of [Yes %] you are counting only the rows with "No" if that's what you have in the slicer and not the total. So it is perfectly possible to get a value above 100%
@AlB in the slicer, there is the YES and NO option, when i select "Yes", the measure turns to 100%(expected), but when i select NO, it returns over 100%, instead of a black. The denopmnator of the YES %, i did COUNTA(Merge[heard of us]), this should count all rows regardless.
Can you help me out with this ?
@Anonymous wrote:
@AlB in the slicer, there is the YES and NO option, when i select "Yes", the measure turns to 100%(expected), but when i select NO, it returns over 100%, instead of a black. The denopmnator of the YES %, i did COUNTA(Merge[heard of us]), this should count all rows regardless.
Nope. It shouldn't. COUNTA(Merge[heard of us]) is directly affected by any active filter so if you're filtering for "No" with the slicer, it will count the Noes only. When you filter for "Yes", you get 100% because numerator always counts the number of Yes, irrespective of the slicer value, and the denominator counts whatever you have in the slicer, Yes in this case, so 100%
If you want to count all rows irrespective of the value in the slicer and thus filter context, you need an ALL with the CALCULATE:
CALCULATE( COUNTA(Merge[heard of us]), ALL(Merge[heard of us]) )
assuming Merge[heard of us] is the only column you are filtering on
@AlB following your calculation, it gives a static value of 74% regardless of the value in the slicer.
This is my case here, I have a column of something like the below:
A B
1 yes
2 yes
3 No
4 yes
5 No
All I want to do here is, get the percentage of "Yes" values, when the value of the slicer is equals to "NO", it shld be blank and when it is "Yes", it should be equals to 100%. This seems easy, but power bi being Power bi, its giving me something else.
Ok, give this a try
CountofHeards = var choice = SELECTEDVALUE('Table'[Heardofus?]) RETURN if ( choice = "No", BLANK(), CALCULATE(COUNTA('Table'[Heardofus?]), 'Table'[Heardofus?] = "Yes") )
//Using this in % calculation should give you a percentage of yes values in the whole table
TotalCounts = CALCULATE ( COUNTA('Table'[Heardofus?]), all('Table'[Heardofus?]) )
//Using this in % calculation should give you 100% everytime you select Yes TotalCounts = CALCULATE ( [CountofHeards], all('Table'[Heardofus?]) )
% heard = [CountofHeards]/[TotalCounts]
hi @atif-hafeez , we are almost there, I used your images 1, 3 and 4. now regardless of any selection in the slicer, its always showing 100% and when i select "NO", it returns a blank. I want it showing the percentage of yes, when nothing is selected, when "Yes" is selected, it should show 100% and when "NO" is selected, i should get blank. Can this done ?
@Anonymous
Hi, try with this:
CountYes = CALCULATE(COUNTA(Table1[A]),FILTER(Table1,Table1[B]="yes"))
%Yes of Total = DIVIDE([CountYes],CALCULATE(COUNTA(Table1[A]),ALLSELECTED(Table1)))
Regards
Victor
Lima - Peru
Here you go my friend. Please accept this as correct if this meets your requirements
Edit:
Slightly modified the TotalifYes variable
CountofYesHeard = CALCULATE(COUNTA('Table'[Heardofus?]), 'Table'[Heardofus?] = "Yes")
TotalCounts = VAR choice = SELECTEDVALUE('Table'[Heardofus?]) VAR TotalifYes = [CountofYesHeard], VAR Total = CALCULATE ( COUNTA('Table'[Heardofus?]), all('Table'[Heardofus?]) ) RETURN SWITCH ( choice, "No",BLANK(), "Yes", TotalifYes, Total )
% heard = DIVIDE([CountofYesHeard],[TotalCounts], BLANK())
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
85 | |
79 | |
54 | |
39 | |
35 |
User | Count |
---|---|
102 | |
80 | |
48 | |
48 | |
48 |