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
jwbecalm
Frequent Visitor

How to calculate the count of a no unique column?

If I have a table like below, Cell Name is unique, but Site Name contain one or more Cell Name,

and the socre for each Cell Name may be same or not.

Site NameCell NameScoreProvince
Site1Cell1300A
Site2Cell2100A
Site2Cell350A
Site3Cell4200B
Site3Cell5400B
Site3Cell6100B
Site4Cell7200B
Site4Cell8300B
Site5Cell9200C
Site5Cell10200C
Site5Cell11200C

Now if Want to Calculate: for different province,  the number of Site Name in which the distinct count of Score is greater than 1.
How do I write the measure?

 

The following is calcuate by manaualy.

because the distinct count of Score for each site is :

Site Name  distinct count of the Score

Site1           1

Site2           2 ( the distinct count of Score is greater than 1.)

Site3           3 ( the distinct count of Score is greater than 1.)

Site4           2 ( the distinct count of Score is greater than 1.)

Site5           1

 

So the final result shoule be:

Porvince    new measure(distinct Site Name in which distinct score >1 )

A               1(which is site2)

B               2(which is site3 and site4)

C               0

9 REPLIES 9
Zubair_Muhammad
Community Champion
Community Champion

Hi @jwbecalm

 

Just Put number in the VALUE field and Choose Distinct Count

 

8312.png

hi, Zubair, sorry for my description, the help is update, please help.thx

@jwbecalm

 

This MEASURE hopefully

 

Measure =
COUNTX (
    FILTER (
        ALL ( TableName[Site Name] ),
        CALCULATE ( DISTINCTCOUNT ( TableName[Score] ) ) > 1
    ),
    CALCULATE ( DISTINCTCOUNT ( TableName[Site Name] ) )
)

Thank you very much, @Zubair_Muhammad

But I am begineer of DAX, it's confusing to me...

I know the first parameter of COUNTX is a table, 

COUNTX(<table>,<expression>) 

So I try to copy this segment of code to create a new table

Filter table = FILTER (
        ALL ( TableName[Site Name] ),
        CALCULATE ( DISTINCTCOUNT ( TableName[Score] ) ) > 1
    )

 and I get this Filter table

Site Name
Site2
Site3
Site4


The next step is to use this Filter table in the COUNTX function:

@jwbecalm

 

You donot have to create a separate Table.

The MEASURE takes care of it.

 

You can think of it as a temporary table which MEASURE creates for the purpose of its MEASUREMENT

 

 

 

 

Thank u, I understand a bit.

 

I just want to konw it better. so I deal it seperately.

 

I don't create a sepearate table, I just want to understand the result of each step.

 

Here, we must use ALL function to create the temp table? or we can use CALCULATETABLE to instead of? 

 

Because ALL seems have some filter igore function

ALL Function (DAX)

 

Returns all the rows in a table, or all the values in a column, ignoring any filters that might have been applied. This function is useful for clearing filters and creating calculations on all the rows in a table.

 
Here in this scenario, we do not need the filter ignore function.
 
 
The second question is: 
Why the first DISTINCTCOUNT, you use CALCUATE before it: 
CALCULATE ( DISTINCTCOUNT ( 'tablename'[Score] ) ) > 1
 
but for the second one, you only use DISTINCTCOUNT?
 DISTINCTCOUNT ( 'tablename'[Site Name] ) )
 
Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi @jwbecalm

 

Please try this calculated measure

 

Measure = COUNTA('Table1'[Cell Name])

And add to a visual with just the 'Site Name' column


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

sorry for my description, the help is update, please help.thx

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.