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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
wolfie777
Frequent Visitor

Count distinct product if contains condition1 and condition2

Hi all. I am trying to work out how to distinct count products if they match the criteria as per below:

wolfie777_0-1627049093426.png

My measure returns count 3 but it should be 2. I need to count only products which match both criteria. Any help will be much appreciated! Thank you 🙂

 

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@wolfie777 try this measure

 

Count = 
SUMX (
    SUMMARIZE (
        'Product',
        'Product'[Product],
        "@Count",
        COUNTROWS ( 
            CALCULATETABLE ( 
                VALUES ( 'Product'[Criteria] ), 
                'Product'[Criteria] IN { "A", "B" }
            ) 
        )
    ),
    IF ( [@Count] = 2, 1 )
)

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

7 REPLIES 7
Pragati11
Super User
Super User

HI @wolfie777 ,

 

You can try creating the following measure:

flag3 = 
CALCULATE
(
    DISTINCTCOUNT('Table (5)'[Criteria]), 
    FILTER(
        ALL('Table (5)'), 'Table (5)'[Product] <= MAX('Table (5)'[Product]) && 'Table (5)'[Criteria] IN {"A", "B"}
        )
)

Now move this measure to the card visual and you will get the required output.

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Thanks @Pragati11, I tried your solution but it didn't work. It needs to be distinct count of product not criteria.

wolfie777_0-1627057637764.png

 

zzcc
Frequent Visitor

HI, @wolfie777 

 

try to create 2 measures like this:

isContain = 
var _table=FILTER(ALL('Table'),[Product]=MAX('Table'[Product]))
var _product=SUMMARIZE(_table,[Criteria])
var _if=IF(("A"in _product)&&("B"in _product),1)
return _if
count = CALCULATE(DISTINCTCOUNT('Table'[Product]),FILTER(ALL('Table'),[isContain]=1))

 

result:

zzcc_0-1627055984024.png

parry2k
Super User
Super User

@wolfie777 try this measure

 

Count = 
SUMX (
    SUMMARIZE (
        'Product',
        'Product'[Product],
        "@Count",
        COUNTROWS ( 
            CALCULATETABLE ( 
                VALUES ( 'Product'[Criteria] ), 
                'Product'[Criteria] IN { "A", "B" }
            ) 
        )
    ),
    IF ( [@Count] = 2, 1 )
)

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thank you so much @parry2k it works! 

wolfie777_1-1627057785857.png

 

selimovd
Super User
Super User

Hey @wolfie777 ,

 

I think the 3 are correct. You filter for Criteria A or B. When you filter that table there are left:

Product 1

Product 2 

Product 5

 

Then the distinct count is 3.

Did you want to calculate something different?

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

Thank you @selimovd. I need to achieve result 2 so need to adjust my measure. It should count distinct products only if they cointain both criteria A and B. I tried many different ways but nothing worked.

wolfie777_0-1627054554945.png

 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Solution Authors
Top Kudoed Authors