Forum Discussion

Raindeer's avatar
Raindeer
Frequent Visitor
8 years ago

Countif for row based count (A:A=A2)

Hi All,

 

I have spend over 4 hours n trying to find answer for following but it looks like no one has asked this specific question so far.

 

I have 100k repeated values in column A and I have to get the number of times each value appears. To do this I use countif in Excel: =Countif(A:A=A2). How can I run same calculation in Power BI?

 

 

I found that following gave me exactly what I wanted: 

CALCULATE(COUNT(Table[Column]),ALL(Table),Table[Column]=EARLIER(Departures[Column]))

 

 

16 Replies

  • Hi Raindeer,

     

    If you add the Values to a table and then add it again and select Count it will give you the expected result.

     

    If you want  measure you need to do something like:

     

    Count = COUNT ( TABLE[Column])

    The measures are calculated based on the context so if you have a value as a row context it will make a filter of the count based on that row.

     

    Regards,

    MFelix

    • Raindeer's avatar
      Raindeer
      Frequent Visitor

      I just tried this solution but it only returns 1 for each value. I know there are supposed to be atleast 8 entries per value.  You will notice in the picture that some values appear multiple times.

       

      Just to give you a bit of context, I am trying to calculate the number of times an activity takes place within one hour for a given date. Activity ID are unique and only appear once a day everyday. 

      • MFelix's avatar
        MFelix
        Super User

        Hi Raindeer,

         

        Are you making a Count or a Count distintc? 

         

        Regards,

        MFelix

  • Anonymous's avatar
    Anonymous
    Not applicable

    Try this

     

    If your date only have a single column "Values", create a column and use the following Dax

     

    Count_Same_Value = CALCULATE(COUNT('Table'[Values]))

    If your date have more than one columns, use the following Dax

     

    Count_Same_Value = CALCULATE(COUNT('Table'[Values]),ALLEXCEPT('Table','Table'[Values]))

     

     

    • Raindeer's avatar
      Raindeer
      Frequent Visitor

      Hi Jessica,

       

      Do you think you can help me find a solution to this problem?

       

      Kind regards

       

      R

  • Jenna619's avatar
    Jenna619
    Regular Visitor

    In your solution: 

    CALCULATE(COUNT(Table[Column]),ALL(Table),Table[Column]=EARLIER(Departures[Column]))

    Where does the Departures[Column] come from?