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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
yellowold5
Helper I
Helper I

Count rows if same category and same product

Hi all, I wanna create a calculate column ex: have two columns, one category and product.
If same category and have product A and b then 1 for category if not then 0 look at screenshot:

CategoryproductOutcome
AA1
AB0
AC0
AD0
AE0
AF0
AG0
AH0
BC0
BD0
CA1
CB0
CC0
CD0
CE0

thanks

1 ACCEPTED SOLUTION

@yellowold5 ,

try this measure,

Category Count = 
CALCULATE(
    DISTINCTCOUNT('Table'[Category]),
    'Table'[product] IN {"A","B"})




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


View solution in original post

5 REPLIES 5
aduguid
Super User
Super User

Try this calculated column 

Outcome = 
VAR currentCategory = [Category]
VAR hasProductA = 
    CALCULATE(
        COUNTROWS('Table'),
        'Table'[Category] = currentCategory,
        'Table'[Product] = "A"
    ) > 0
VAR hasProductB = 
    CALCULATE(
        COUNTROWS('Table'),
        'Table'[Category] = currentCategory,
        'Table'[Product] = "B"
    ) > 0
RETURN
    IF(hasProductA && hasProductB, 1, 0)

Hi got 0 as outcome

@yellowold5 ,

I have made a small modification to the DAX provided by @aduguid . Could you please check if it is working correctly?

Outcome = 
VAR hasProductA = 
    CALCULATE(
        COUNTROWS('Table'),
        'Table'[Category] = "A",
        'Table'[Product] = "A"
    ) 
VAR hasProductB = 
    CALCULATE( 
        COUNTROWS('Table'),
        'Table'[Category] = "B",
        'Table'[Product] = "B"
    ) 
RETURN
IF(hasProductA = 1 || hasProductB = 1 , 1, 0)

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


Hi, thanks for your support is possible to have as my outcome? i want to sum how many category whos have product a and b.

@yellowold5 ,

try this measure,

Category Count = 
CALCULATE(
    DISTINCTCOUNT('Table'[Category]),
    'Table'[product] IN {"A","B"})




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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