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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Count distinct rows based on multiple columns

Hi 

Can someone please help me with the Dax?
Need to count distinct rows based of three different columns - Category A, Catgeory B and Color = Red
If the row is duplicate - count only once. 

Sample Table -

Rid123_2-1632964491600.png

 


Expected Output - 

Category A Count
A3
B1


Thanks in advance

2 ACCEPTED SOLUTIONS
VahidDM
Super User
Super User

Hi @Anonymous 

 

It seems your calculation was based on 4 columns because row 5 in your data is the same as row 1 based on Category A and Category B, and Color. (so, in the result for A, it should be 2, not 3).

But if you want the result based on the three categories and color=Red,

 

1- Add a new colum with this code :

 

 

 

New Column = 
'Table'[Category A]&'Table'[Category B]&'Table'[Category C]
//If you want the distinc count based on Cat A and B, remove "&'Table'[Category C]" from end of the code

 

 

 

2- try this measure to find the count distinct rows:

 

 

 

Measure = 
CALCULATE (
    DISTINCTCOUNT ( 'Table'[New Column] ),
    FILTER ( 'Table', 'Table'[Color] = "Red" )
)

 

 

 

 

Output:

VahidDM_0-1632968920964.png

 

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

Appreciate your Kudos🙏!!

 

 

View solution in original post

Jihwan_Kim
Super User
Super User

Hi,

In my opinion, if you are "counting rows - distinct" based on more than two columns, the DAX function - SUMMARIZE helps.

 

Picture1.png

 

Expected result measure : =
COUNTROWS (
FILTER (
SUMMARIZE ( Data, Data[Category B], Data[Category C], Data[Color] ),
Data[Color] = "red"
)
)
 
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

In my opinion, if you are "counting rows - distinct" based on more than two columns, the DAX function - SUMMARIZE helps.

 

Picture1.png

 

Expected result measure : =
COUNTROWS (
FILTER (
SUMMARIZE ( Data, Data[Category B], Data[Category C], Data[Color] ),
Data[Color] = "red"
)
)
 
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
VahidDM
Super User
Super User

Hi @Anonymous 

 

It seems your calculation was based on 4 columns because row 5 in your data is the same as row 1 based on Category A and Category B, and Color. (so, in the result for A, it should be 2, not 3).

But if you want the result based on the three categories and color=Red,

 

1- Add a new colum with this code :

 

 

 

New Column = 
'Table'[Category A]&'Table'[Category B]&'Table'[Category C]
//If you want the distinc count based on Cat A and B, remove "&'Table'[Category C]" from end of the code

 

 

 

2- try this measure to find the count distinct rows:

 

 

 

Measure = 
CALCULATE (
    DISTINCTCOUNT ( 'Table'[New Column] ),
    FILTER ( 'Table', 'Table'[Color] = "Red" )
)

 

 

 

 

Output:

VahidDM_0-1632968920964.png

 

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

Appreciate your Kudos🙏!!

 

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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