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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Abdulazizmq_16
New Member

Distinct count only if all values in another column are met

Dears, 

 

I would like to distinct count values in the standard column on multiple conditions in another compliance status column. 

I have 4 compliance status: complianced, partly complianced, not complianced, NA

 

Condition 1:  distinct count standard as complianced if all values in compliance status is only complianced 

Condition 2:  distinct count standard as partly complianced if values in compliance status are mix of complianced, partly complianced and/or not complianced

Condition 3:  distinct count standard as not complianced if values in compliance status is only not complianced

Condition 4:  distinct count standard as NA if all values in compliance status is only NA

 

StandardStandard requirementsCompliance status
5.1.15.1.1.1complianced 
5.1.15.1.1.2complianced 
5.1.25.1.2.1complianced 
5.1.25.1.2.2partaly complianced 
5.1.25.1.2.3not complianced 
5.1.25.1.2.4complianced 
5.1.35.1.3.1not complianced 
5.1.35.1.3.2not complianced 
5.1.45.1.4.1NA
5.1.45.1.4.2NA
5.1.55.1.5.1complianced 

 

example above there are 5 standards,

# of complianced is 2

# of partaly complianced is 1

# of not complianced is 1

# of NA is 1

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

@Abdulazizmq_16 

Give these measures a try.

Complianced = 
VAR _Other = CALCULATETABLE( DISTINCT ( 'Your Table'[Standard] ), 'Your Table'[Compliance status] <> "complianced" )
RETURN
    CALCULATE ( 
        DISTINCTCOUNT ( 'Your Table'[Standard] ), 
        NOT ( 'Your Table'[Standard] IN ( _Other ) )
    )
NA = 
VAR _Other = CALCULATETABLE ( DISTINCT ( 'Your Table'[Standard] ), 'Your Table'[Compliance status] <> "NA" )
RETURN
    CALCULATE ( 
        DISTINCTCOUNT ( 'Your Table'[Standard] ), 
        NOT ( 'Your Table'[Standard] IN ( _Other ) )
    )
Not Complianced = 
VAR _Other = CALCULATETABLE ( DISTINCT ( 'Your Table'[Standard] ), 'Your Table'[Compliance status] <> "not complianced" )
RETURN
    CALCULATE ( 
        DISTINCTCOUNT ( 'Your Table'[Standard] ), 
        NOT ( 'Your Table'[Standard] IN ( _Other ) )
    )
Partly Complianced = 
COUNTROWS (
    FILTER (
        VALUES ( 'Your Table'[Standard] ),
        CALCULATE (
            COUNTROWS (
                SUMMARIZE (
                    'Your Table',
                    'Your Table'[Standard],
                    'Your Table'[Compliance status]
                )
            )
        ) > 1
    )
)

jdbuchanan71_0-1717366004719.png

View solution in original post

7 REPLIES 7
jdbuchanan71
Super User
Super User

I would do a measure that is ONLY Partly Complianced because that is one of your distinct statuses

Do one that is "mixed" (a combination, excluding NA).

Then add those together.

I added some to the example, where doe 5.1.8 belong because it has partial and NA?

jdbuchanan71_0-1717378257571.png

I attached my sample for you to look at.

 

It's my mistake, when a standard is NA, that means all standard's details are NA, 

 

So if 5.1.8 is NA, all details standard (5.1.8.1, 5.1.8.2) are NA

Also 5.1.2.4 I changed it to complianced 

jdbuchanan71
Super User
Super User

So Partly Compliance does not include "NA"?  It is the combiniation of those that are only "Partly Complianced" and those that are a mix of "* compliance"?

Where do you count one that has NA and Partial Compliance?

Yes, does not include NA, 

Partly Complianced could be one of these conditions if standard requirements:

1- mix of complianced & not complianced 

2- mix of complianced & partly complianced 

3- mix of not complianced & partly complianced 

4- only partly complianced 

5- mix of complianced & partly complianced  & not complianced 

jdbuchanan71
Super User
Super User

@Abdulazizmq_16 

Give these measures a try.

Complianced = 
VAR _Other = CALCULATETABLE( DISTINCT ( 'Your Table'[Standard] ), 'Your Table'[Compliance status] <> "complianced" )
RETURN
    CALCULATE ( 
        DISTINCTCOUNT ( 'Your Table'[Standard] ), 
        NOT ( 'Your Table'[Standard] IN ( _Other ) )
    )
NA = 
VAR _Other = CALCULATETABLE ( DISTINCT ( 'Your Table'[Standard] ), 'Your Table'[Compliance status] <> "NA" )
RETURN
    CALCULATE ( 
        DISTINCTCOUNT ( 'Your Table'[Standard] ), 
        NOT ( 'Your Table'[Standard] IN ( _Other ) )
    )
Not Complianced = 
VAR _Other = CALCULATETABLE ( DISTINCT ( 'Your Table'[Standard] ), 'Your Table'[Compliance status] <> "not complianced" )
RETURN
    CALCULATE ( 
        DISTINCTCOUNT ( 'Your Table'[Standard] ), 
        NOT ( 'Your Table'[Standard] IN ( _Other ) )
    )
Partly Complianced = 
COUNTROWS (
    FILTER (
        VALUES ( 'Your Table'[Standard] ),
        CALCULATE (
            COUNTROWS (
                SUMMARIZE (
                    'Your Table',
                    'Your Table'[Standard],
                    'Your Table'[Compliance status]
                )
            )
        ) > 1
    )
)

jdbuchanan71_0-1717366004719.png

That code worked for partly complianced

 

 

(COUNTROWS (
    FILTER (
        VALUES ( 'Your Table'[Standard] ),
        CALCULATE (
            COUNTROWS (
                CALCULATETABLE(
                    SUMMARIZE (
                        'Your Table',
                        'Your Table'[Standard],
                        'Your Table'[Compliance status]
                    ),
                    'Your Table'[Compliance status] <> "NA"
                )
            )
        ) > 1
    )
))
+
(
    VAR _Other = 
    CALCULATETABLE(
        DISTINCT('Your Table'[Standard]),
        'Your Table'[Compliance status] <> "not complianced"
        )
RETURN
CALCULATE(
    DISTINCTCOUNT('Your Table'[Standard]),
        NOT('Your Table'[Standard] IN (_Other))
    )
)

 

Note: NA must be applied to all standard requirements, other ways it would not be counted

 

Thank you so much. all of them worked properly except partly complianced doesn't work.

Note: it could be a mix of:

1- complianced & not complianced 

2- complianced & partly complianced 

3- not complianced & partly complianced 

4- only partly complianced 

5- complianced & partly complianced  & not complianced 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.