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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

COUNT Distinct Column A if SUM of Column B = 0

Hello,

 

I have the following dataset:

 

StatusTransaction RulesTotal # of Complaints
ActiveRule Alpha 107
ActiveRule Bravo0
ActiveRule Bravo0
ActiveRule Charlie6
ActiveRule Charlie0
ActiveRule Delta13
ActiveRule Delta64
ActiveRule Delta12
ActiveRule Echo0
InactiveRule Foxtrot3
InactiveRule Foxtrot0

 

I'm trying to create a Measure I can throw into a Card that will show the following:

  • No. of Active Unique "Transaction Rules" with 0 Complaints.
    • So as an example, for the above - this would be 2 Rules (Bravo and Echo)
    • I'm thinking that I need to create a Count Distinct of each of the Rule's, Filtered for "Active" and SUM within the Filtered Rule = 0.
    • Unsure how to create the above Measure to meet the above criteria?
  • Conversely, the No. of Active "Transaction Rules" with at-least 1 Complaint
    • So, again for above - this would be 3 (Alpha, Charlie and Delta)
    • This would be Count Distinct again, and then filtered out for Inactive transaction rules. And then sum the no. of complaints, so if sum<>0 then it is counted.

Hopeful to see what people come up with. I have the following, but it doesn't seem to work: 

 

Measure 1 =
CALCULATE(
    COUNTROWS(DISTINCT('Table1'[Transaction Rules])),FILTER('Table1',SUM([Tot_Complaints]) = 0,[Status] = "Active)

 

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Measures

count_ac&0 =
VAR s =
    SUMMARIZE (
        FILTER ( 'Table', 'Table'[Status] = "Active" ),
        'Table'[Transaction Rules],
        "sum", SUM ( 'Table'[Total # of Complaints] )
    )
RETURN
    COUNTROWS ( FILTER ( s, [sum] = 0 ) )


count&in>0 =
VAR s =
    SUMMARIZE (
        FILTER ( 'Table', 'Table'[Status] = "Active" ),
        'Table'[Transaction Rules],
        "sum", SUM ( 'Table'[Total # of Complaints] )
    )
RETURN
    COUNTROWS ( FILTER ( s, [sum] > 0 ) )

Capture1.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Measures

count_ac&0 =
VAR s =
    SUMMARIZE (
        FILTER ( 'Table', 'Table'[Status] = "Active" ),
        'Table'[Transaction Rules],
        "sum", SUM ( 'Table'[Total # of Complaints] )
    )
RETURN
    COUNTROWS ( FILTER ( s, [sum] = 0 ) )


count&in>0 =
VAR s =
    SUMMARIZE (
        FILTER ( 'Table', 'Table'[Status] = "Active" ),
        'Table'[Transaction Rules],
        "sum", SUM ( 'Table'[Total # of Complaints] )
    )
RETURN
    COUNTROWS ( FILTER ( s, [sum] > 0 ) )

Capture1.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , Try something like

if(SUM('Table1'[Tot_Complaints]) = 0,DISTINCT('Table1'[Transaction Rules]),SUM('Table1'[Tot_Complaints] ))

 

or

if(isblank(SUM('Table1'[Tot_Complaints])) || SUM('Table1'[Tot_Complaints]) = 0,DISTINCT('Table1'[Transaction Rules]),SUM('Table1'[Tot_Complaints] ))

Anonymous
Not applicable

Hi @amitchandak ,

where do I put in a Filter for the Status?

 

Alternatively, I tried something like this but no luck:

 

Measure:
CALCULATE(
    DISTINCTCOUNT('Table1'[Transaction Rules]),
    filter('Table1','Table1'[Status] = "Active" && 'Table1'[Tot_Complaints] <> 0)
)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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