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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
caito103
Helper I
Helper I

Calculate Distinct Count based on value of other column

Hello,

Im trying to count each client of the company if the cell have in the "Clase" column the data "Factura (v)". But, in "Codlegal" column i have multples times each code, so i need to use distinct to no repeat each one.

 

Im trying with:

 

NumClientes = CALCULATE ( DISTINCTCOUNT(Hoja2[Codlegal]);Hoja2[Clase] = "Factura (v)")

 

But i get "30,23K" and are only 2.916. I tried with differents formulas but i cant get it, any advice?

 

1 ACCEPTED SOLUTION

@caito103

 

Try with this: 

 

Measure = CALCULATE(DISTINCTCOUNT(Hoja2[Codlegal]),FILTER(Hoja2,Hoja2[Clase]="Factura (v)"))

 

or also can try with:

 

Measure2 = COUNTROWS(CALCULATETABLE(DISTINCT(Hoja2[CodLegal]),FILTER(Hoja2,Hoja2[Clase]="Factura (v)")))

 

 

 




Lima - Peru

View solution in original post

8 REPLIES 8
Vvelarde
Community Champion
Community Champion

@caito103

 

Hi, are you using a measure ?

 

You should use a measure not a calculated column

 

Victor

Lima - Peru

 




Lima - Peru

If your trying to count the rows, this should work:

NumClientes = CALCULATE ( COUNTROWS(Hoja2),Hoja2[Clase] = "Factura (v)")

 

 

...as a measure

Yes, i did it as a measure:

NumClientes = CALCULATE(COUNTROWS(Hoja2);Hoja2[Clase] = "Factura (v)")

 

But now i dont know how to use distinct with this, can be good use GroupBy function to group by CodLegal and get only one CodLegal if this have the "Factura (v)"? 

I tried to used it but didnt work:

 

NumClientes = GROUPBY ( Hoja2;Hoja2[Codlegal];CALCULATE(COUNTROWS(Hoja2);Hoja2[Clase] = "Factura (v)"))

 

Greetings!

@caito103

 

Try with this: 

 

Measure = CALCULATE(DISTINCTCOUNT(Hoja2[Codlegal]),FILTER(Hoja2,Hoja2[Clase]="Factura (v)"))

 

or also can try with:

 

Measure2 = COUNTROWS(CALCULATETABLE(DISTINCT(Hoja2[CodLegal]),FILTER(Hoja2,Hoja2[Clase]="Factura (v)")))

 

 

 




Lima - Peru

worked! THank you so much!

dtartaglia
Resolver I
Resolver I

Hi,

 

DISTINCTCOUNT counts the values in the column. Can you use COUNTROWS then filter distinct in the visual?

Sorry, but how can i use DISTINCT from the visual filters? I just got filter by value (Factura (v)). 

0F7Zek-mTrqbkLgsQFDxhA

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Thank you so much!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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