Forum Discussion

walkeras's avatar
walkeras
Icon for Advocate I rankAdvocate I
9 years ago
Solved

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.

 

 

 

 

 

  • walkeras's avatar
    walkeras
    9 years ago

    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.

7 Replies

  • wlopezm's avatar
    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's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion

    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"))
    • MarcelBeug's avatar
      MarcelBeug
      Icon for Community Champion rankCommunity Champion

      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.

       

      • Greg_Deckler's avatar
        Greg_Deckler
        Icon for Community Champion rankCommunity Champion

        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".