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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
walkeras
Advocate I
Advocate I

Count the frequency of a boolean value

Hello everyone,

 

I have a database that stores the boolean values of a field that was collected. I am trying to count the frequency that the value appears i.e. the strucutre looks something like this:

 

Element A  | Element B

True           | False

True           | False

False          | True

 

With this I would like to be able to determine that Element A is True twice and False once etc. I have been trying to use measures without much sucess or knowing the functions to use.

 

 

 

 

 

1 ACCEPTED SOLUTION

Hey,

 

Last night I had a brainwave and jumped out of bed and got it working using the following formula:

 

TrueCount = COUNTAX(FILTER('Table',[Element_A]=TRUE()),TRUE())

 

Thanks for the additional inputs as well, I will have a play with those other suggestions to see how else I might be able to solve the problem.

View solution in original post

7 REPLIES 7
wlopezm
Regular Visitor

There is a simplest way to write the formula, and in my opinion, it is easy to read and understand.

 

COUNTROWS(FILTER(Table; Table[Element A] = TRUE()))

Greg_Deckler
Super User
Super User

You do not need measures for this. You could do this in a table visualization by adding Element A and then Count of Element B or Count of Element A.

 

If you wanted a measure, you could do something like:

 

TrueCount = CALCULATE(COUNT([Element A]),FILTER(Table,[Element A] = "True"))

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Shouldn't that be more something like:

 

TrueCount = Calculate(COUNTROWS('Table'),'Table'[Element A])

This assumes that Element A has only true and false values.

 

Specializing in Power Query Formula Language (M)

Well, depends on whether his true/false columns are text or boolean. You can't directly COUNT true/false columns if that's what he has. You can solve that by adding in Index field in the query and counting that instead but either method should work. And using the TRUE() function in place of "True".


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Hey,

 

Last night I had a brainwave and jumped out of bed and got it working using the following formula:

 

TrueCount = COUNTAX(FILTER('Table',[Element_A]=TRUE()),TRUE())

 

Thanks for the additional inputs as well, I will have a play with those other suggestions to see how else I might be able to solve the problem.

Hi,

 

My scenario is something similar but I have many conditions. Like below
if category="Good" then count(Column)

else if category = "bad" then count(Column)

else if category ="neutral" then count(Column)

else

blank()

END

How do i do this?
I tried it with if and switch condition but its not working.
CheckCount =
IF([Category]="Danger",COUNT(Table1[Column1]),
IF([Category]="Bad",COUNT(Table1[Column1]),
IF([Category]="Good",COUNT(Table1[Column1]),
IF([Category]="Neutral",COUNT(Table1[Column1]),
IF([Category]="very Good",COUNT(Table1[Column1])
,BLANK())
) ) ) )

And this category is a measure which I have made. But now i just want a count of these categories so i can make some pie ot donought chart.

Thank you,
Bhavana

Worked like a charm for me! Thanks!!!

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.