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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
yellowold5
Helper I
Helper I

distinctcount id depending on values

Hi, I need help to distinctcount id base if it cointains in same category:

IDproductiddesciptionABC
11frozen1  
21frozen1  
31frozen  1
32fresh  1
41frozen  1
42fresh  1
52fresh 1 
Total  212

In the tabel I want to distinctcount the ID base on desciprtion:
If in same id but have in description only cointains frozen then A is 1
If in same id but have in description only cointains fresh then B is 1
If in same id but have in both description cointains both frozen and fresh then c is 1

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @yellowold5 ,

I think maybe you can try these steps below:

I create a table as you mentioned.

vyilongmsft_0-1726631503912.png

Then I think you can create a new table and here is my DAX code.

NewTable =
ADDCOLUMNS (
    SUMMARIZE ( 'Table', 'Table'[ID], 'Table'[productid], 'Table'[desciption] ),
    "A",
        IF (
            CALCULATE (
                COUNTROWS ( 'Table' ),
                ALLEXCEPT ( 'Table', 'Table'[ID] ),
                'Table'[desciption] = "frozen"
            )
                = CALCULATE ( COUNTROWS ( 'Table' ), ALLEXCEPT ( 'Table', 'Table'[ID] ) ),
            1,
            BLANK ()
        ),
    "B",
        IF (
            CALCULATE (
                COUNTROWS ( 'Table' ),
                ALLEXCEPT ( 'Table', 'Table'[ID] ),
                'Table'[desciption] = "fresh"
            )
                = CALCULATE ( COUNTROWS ( 'Table' ), ALLEXCEPT ( 'Table', 'Table'[ID] ) ),
            1,
            BLANK ()
        ),
    "C",
        IF (
            CALCULATE (
                COUNTROWS ( 'Table' ),
                ALLEXCEPT ( 'Table', 'Table'[ID] ),
                'Table'[desciption] = "frozen"
            ) > 0
                && CALCULATE (
                    COUNTROWS ( 'Table' ),
                    ALLEXCEPT ( 'Table', 'Table'[ID] ),
                    'Table'[desciption] = "fresh"
                ) > 0,
            1,
            BLANK ()
        )
)

 Finally you will get what you want.

vyilongmsft_1-1726631621598.png

 

 

 

Best Regards

Yilong Zhou

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
Anonymous
Not applicable

Hi @yellowold5 ,

I think maybe you can try these steps below:

I create a table as you mentioned.

vyilongmsft_0-1726631503912.png

Then I think you can create a new table and here is my DAX code.

NewTable =
ADDCOLUMNS (
    SUMMARIZE ( 'Table', 'Table'[ID], 'Table'[productid], 'Table'[desciption] ),
    "A",
        IF (
            CALCULATE (
                COUNTROWS ( 'Table' ),
                ALLEXCEPT ( 'Table', 'Table'[ID] ),
                'Table'[desciption] = "frozen"
            )
                = CALCULATE ( COUNTROWS ( 'Table' ), ALLEXCEPT ( 'Table', 'Table'[ID] ) ),
            1,
            BLANK ()
        ),
    "B",
        IF (
            CALCULATE (
                COUNTROWS ( 'Table' ),
                ALLEXCEPT ( 'Table', 'Table'[ID] ),
                'Table'[desciption] = "fresh"
            )
                = CALCULATE ( COUNTROWS ( 'Table' ), ALLEXCEPT ( 'Table', 'Table'[ID] ) ),
            1,
            BLANK ()
        ),
    "C",
        IF (
            CALCULATE (
                COUNTROWS ( 'Table' ),
                ALLEXCEPT ( 'Table', 'Table'[ID] ),
                'Table'[desciption] = "frozen"
            ) > 0
                && CALCULATE (
                    COUNTROWS ( 'Table' ),
                    ALLEXCEPT ( 'Table', 'Table'[ID] ),
                    'Table'[desciption] = "fresh"
                ) > 0,
            1,
            BLANK ()
        )
)

 Finally you will get what you want.

vyilongmsft_1-1726631621598.png

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

dharmendars007
Super User
Super User

Hello @yellowold5 , 

 

Please try creating this measures for A,B, and C and add it in the table..

 

Count_A =
CALCULATE(
DISTINCTCOUNT(TableName[ID]),
NOT(CONTAINS(TableName, TableName[productdescription], "fresh")),
CONTAINS(TableName, TableName[productdescription], "frozen"))

 

Count_B =
CALCULATE(
DISTINCTCOUNT(TableName[ID]),
NOT(CONTAINS(TableName, TableName[productdescription], "frozen")),
CONTAINS(TableName, TableName[productdescription], "fresh"))

 

Count_C =
CALCULATE(
DISTINCTCOUNT(TableName[ID]),
CONTAINS(TableName, TableName[productdescription], "frozen"),
CONTAINS(TableName, TableName[productdescription], "fresh"))

 

If you find this helpful , please mark it as solution and Your Kudos are much appreciated!

 

Thank You

Dharmendar S

LinkedIN 

Hi, got this error:
A function 'CONTAINS' has been used in a True/False expression that is used as a table filter expression. This is not allowed.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

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

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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