Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago

Count If in Power BI

Hi everyone.

I'm want calculate like count if excel in power BI, but my sentence is not ok. I'm try create another measure, but this count all register for each operator.

 

MeasureCountIf =
CALCULATE (
COUNTROWS ( Table );
FILTER ( Table; Table[Operator] = Table[Operator] );
FILTER ( Table; Table[Serial Number] = Table[Serial Number] )
)

 

Thanks for help.

 

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    HI Anonymous,

     

    Which logic you want to used to link these conditions?  AND or OR?

     

    In addition, you can take a look at following formula if it suitable for your requirement:

     

    And Logic =
    VAR currOpe =
        SELECTEDVALUE ( Table[Operator] )
    VAR currSer =
        SELECTEDVALUE ( Table[Serial Number] )
    RETURN
        COUNTROWS (
            FILTER (
                ALLSELECTED ( Table );
                Table[Operator] = currOpe
                    && Table[Serial Number] = currSer
            )
        )
    
    Or Logic =
    VAR currOpe =
        SELECTEDVALUE ( Table[Operator] )
    VAR currSer =
        SELECTEDVALUE ( Table[Serial Number] )
    RETURN
        COUNTROWS (
            FILTER (
                ALLSELECTED ( Table );
                Table[Operator] = currOpe
                    || Table[Serial Number] = currSer
            )
        )
    

     

    Regards,

    Xiaxoin Sheng

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello Xiaxoin, thanks for your reply.

       

       

      I used your solution for AND, but not solve. When i put this measure, not appear all my operator.

      Appear only one. 

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Anonymous,

         

        Is there any summary on your records? AFAIK, SELECTEDVALUE function not works on summary records.

        If this is a case, you need to use other functions to get current row contents.

        And Logic =
        VAR currOpe =
            FIRSTNONBLANK ( Table[Operator]; [Operator] )
        VAR currSer =
            MAX ( Table[Serial Number] )
        RETURN
            COUNTROWS (
                FILTER (
                    ALLSELECTED ( Table );
                    Table[Operator] = currOpe
                        && Table[Serial Number] = currSer
                )
            )
        
        
        Or Logic =
        VAR currOpe =
            FIRSTNONBLANK ( Table[Operator]; [Operator] )
        VAR currSer =
            MAX ( Table[Serial Number] )
        RETURN
            COUNTROWS (
                FILTER (
                    ALLSELECTED ( Table );
                    Table[Operator] = currOpe
                        || Table[Serial Number] = currSer
                )
            )
        

         

        Regards,

        Xiaoxin Sheng