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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
andreluizrenda
Frequent Visitor

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 3
v-shex-msft
Community Support
Community Support

HI @andreluizrenda,

 

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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. 

 

Hi @andreluizrenda,

 

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.