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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Alvarom1
Helper I
Helper I

Help on DAX-DISTINCTOUNT

Hi

I want to calculate a number of distinctcount for this table

 

LetterColor
aWhite
aRed
bWhite
cWhite
cRed
dRed
eWhite
f 
gWhite
gRed
iRed

 

and i need to calculate the distinct count of letters that have onle "White". In this simple case the result it would be 2 (letters b & e).

Can you help me on using that to make the calculation with DAX?

Many thanks

Alvaro

1 ACCEPTED SOLUTION

hi, @Alvarom1 

You could try this way as below to get it:

Step1:

Create a measure that DISTINCTCOUNT different colors of each letter.

different colors each Letter = CALCULATE(DISTINCTCOUNT('Table'[Color]))

Step2:

Create a measure that DISTINCTCOUNT while colors of each letter.

Only white each letter = CALCULATE(DISTINCTCOUNT('Table'[Letter]),FILTER('Table','Table'[Color]="White"))

Step3:

Then use this measure to get your requirement:

Result = CALCULATE(DISTINCTCOUNT('Table'[Letter]),FILTER(VALUES('Table'[Letter]),[different colors each Letter]=[Only white each letter]))

Result:

7.JPG

 

and here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
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

7 REPLIES 7
amitchandak
Super User
Super User

Try

calculate(DISTINCTCOUNT(letter),color="White")

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks.

Thanks for your reply. But with that the result is 5 as it includes the letters that have "White" but also "Red". The result that I am looking for is 2, only letters that have "White" and no other color.

Hope is clear. Any suggestion?

Thanks!

Alvaro

That should filter white

calculate(DISTINCTCOUNT(letter),color="White")

Other solution

calculate(DISTINCTCOUNT(letter),filter(table,color="White"))

Thanks again, but with that I do not get the expected result that is the distinct count of letters that have ONLY "White", excluding the letters that have "White" and "Red" , that in this table are letters "b" and "e", that is 2 letters. Your formula gives me 5 as result but what I expect is 2

 

Makes it sense?

 

Thanks again!

 

Alvaro 

 

@amitchandak 

hi, @Alvarom1 

You could try this way as below to get it:

Step1:

Create a measure that DISTINCTCOUNT different colors of each letter.

different colors each Letter = CALCULATE(DISTINCTCOUNT('Table'[Color]))

Step2:

Create a measure that DISTINCTCOUNT while colors of each letter.

Only white each letter = CALCULATE(DISTINCTCOUNT('Table'[Letter]),FILTER('Table','Table'[Color]="White"))

Step3:

Then use this measure to get your requirement:

Result = CALCULATE(DISTINCTCOUNT('Table'[Letter]),FILTER(VALUES('Table'[Letter]),[different colors each Letter]=[Only white each letter]))

Result:

7.JPG

 

and here is sample pbix file, please try it.

 

Regards,

Lin

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

HI Again,

as I confirmed, it works.

The issue that I have now is that the database is big and when it comes to calculate the last measure it takes a long time (several minutes) until the result appears.

Any idea to make it faster?

Thanks

Alvaro

 

@v-lili6-msft 

It works!

Thanks a lot

Alvaro

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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