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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
aloosh89
Helper I
Helper I

Getting a distinct count based on another column

 

Hello,

 

I would like to do a distinct count of 'Asset Name'. But when the country is different, I want to be able to count the Asset name again. For example in the below, the first row gets counted, the second row does not get counted, the third and fourth rows get counted. 

 

Please note that the actual table has many other columns and hence no rows are completely unique. 

 

Asset NameCountryOther Columns…
Asset1UK...
Asset1UK...
Asset1Germany...
Asset2Germany...

 

Thanks,

Ali 

2 ACCEPTED SOLUTIONS
Ashish_Mathur
Super User
Super User

Hi,

Try these measures

AC = DISTINCTCOUNT(Data[Asset Name])
Measure = SUMX(VALUES(Data[Country]),[AC])

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

TomMartens
Super User
Super User

Hey @aloosh89 ,

 

you can use this single measure (I prefer a single measure approach):

Measure = 
SUMX(
    VALUES( 'Table'[Country] )
    , CALCULATE(
        DISTINCTCOUNT( 'Table'[Asset Name] )
        , ALLEXCEPT('Table' , 'Table'[Country] )
    )
)

The measure can be used inside.a table and also on a Card visual. The measure creates the value of 3 in the Total of a Table visual and also on a Card visual, but also in a single line of the table visual, I added values to the Other column to simulate your requirement - "the actual table has many other columns and hence no rows are completely unique":
image.png
Hopefully, this provides what you are looking for.

Regards,
Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

6 REPLIES 6
mstew55
Frequent Visitor

How can i count distinct values, that are dipulicates by rows, based on another column. Example. I have column with Names, that can repeat, and i have column with numbers that can be blank by row. I want to Count the names that has all blanks...No row has a number

Hi,

Try this measure

Measure = calculate(distinctcount(Data[Name]),data[Number]=Blank())

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
TomMartens
Super User
Super User

Hey @aloosh89 ,

 

you can use this single measure (I prefer a single measure approach):

Measure = 
SUMX(
    VALUES( 'Table'[Country] )
    , CALCULATE(
        DISTINCTCOUNT( 'Table'[Asset Name] )
        , ALLEXCEPT('Table' , 'Table'[Country] )
    )
)

The measure can be used inside.a table and also on a Card visual. The measure creates the value of 3 in the Total of a Table visual and also on a Card visual, but also in a single line of the table visual, I added values to the Other column to simulate your requirement - "the actual table has many other columns and hence no rows are completely unique":
image.png
Hopefully, this provides what you are looking for.

Regards,
Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Ashish_Mathur
Super User
Super User

Hi,

Try these measures

AC = DISTINCTCOUNT(Data[Asset Name])
Measure = SUMX(VALUES(Data[Country]),[AC])

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
TomMartens
Super User
Super User

Hey @aloosh89 ,

you can create a calculated column using DAX like so:

# of distinct Assets = 
CALCULATE(
    DISTINCTCOUNT( 'Table'[Asset Name] )
    , ALLEXCEPT( 'Table' , 'Table'[Country] )
)

The table will look like this:
image.png
It's required to identify the first row inside a group (defined by Country) if you want to suppress the calculation for subsequent rows in the group.

If you want to use a measure, than this can provide you are looking for:

# of distinct Assets (ms) = 
CALCULATE(
    DISTINCTCOUNT( 'Table'[Asset Name] )
    , ALLSELECTED( 'Table'[Asset Name] )
)

A table visual using the measure:
image.png

I hope this gets you started and helps you tackle your challenge.

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi @TomMartens ,

 

Thanks for providing this solution. What I was hoping for is that the caluclation just returns the count. As in for the example I provided it would return 3. Can you please point me how to do that?

 

Thanks,

Ali 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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