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
ThomasDaSilva
Advocate II
Advocate II

Count the number of value in one column based on another

Hi everyone,

 

I'm trying to create a formula but i need some help.

 

I have a table with a list of client number and paiement code.

Each client can have different paiement code:

 

Code client      paiement Code

10250                    Z1

10250                   Z2

10251                   Z3

10252                   Z4

10252                  Z1

 

My goal is to count the number of different paiement code for each client:

10250             2

10251            1

10252            2

 

 

I've tried measures but without success.

Thank you all 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

 

Drag Code Client to the Row labels and use this measure

 

=DISTINCTCOUNT(Data[paiement code])


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

View solution in original post

17 REPLIES 17
Anonymous
Not applicable

i have a table like this

ID

 SurnameFirst Name
  1234567abcdef
  1234567abcdef
  1234567abcdef
  1234567abcdef
   890123ghklmk
   890123ghklmk
   890123ghklmk
  1111111ggghhh
  1111111ggghhh

 

 

Need a table like this (add a column and count based on column ID

 

 

IDSurnameFirst NameCount 
  1234567abcdef4
  1234567abcdef4
  1234567abcdef4
  1234567abcdef4
   890123ghklmk3
   890123ghklmk3
   890123ghklmk3
  1111111ggghhh3
  1111111ggghhh2

Hi,

Write this calculated column formula

=CALCULATE(COUNTROWS(Data),FILTER(Data,Data[ID]=EARLIER(Data[ID])))

Hope this helps.


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

Smart solution, I tried in one of my works. It is awsome 😊

Thank you.


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

Thanks Ashish ... what is Data refering to ? remember i need to create an additional column aswell.

You are welcome.  That is the name of the Table.  Change it to whatever your Table name is.


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

Thank you

Hi,

If my reply helped, please mark it as Answer.


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

Hi,

 

Drag Code Client to the Row labels and use this measure

 

=DISTINCTCOUNT(Data[paiement code])


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

Capture111.PNG

 

Hello! 

 

I want to calculate distinct values of column A. Which i did by using the distinct function in a measure I created. 

 

Now I want to calculate the total number of "No" for each unique value only. Can anyone please help? @Ashish_Mathur @v-danhe-msft 

 

For example the total should be 3 for "No" as I want to count for Saturday as only 1 not 2 times. 

Hi,

Drag the Not applicable column to the table visual and write this measure

Measure = distinctcount(Data[Day])

Hope this helps.


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

Thanks Ashish, my distinct count is working now but for some reason in both columns it is giving me 1 more value. For example, I checked in excel, where i deleted the duplicate values, the answer excel is giving is 10 hoever my distinct count is giving 11

Hi,

That should not be happening.  Share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-danhe-msft
Employee
Employee

Hi @ThomasDaSilva,

Based on my test, you can refer to below steps:

1.I have entered some sample data like the below picture:

A.PNG2.

2.Create a measure.

Measure = CALCULATE(COUNT(Table1[Code client]),FILTER('Table1','Table1'[Code client]<=MAX('Table1'[Code client])))

3.Create a Table visual and add the related field, now you can see the result.

B.PNG

You can also download the PBIX file to have a view.

https://www.dropbox.com/s/ttunta8z8slai36/Count%20the%20number%20of%20value%20in%20one%20column%20ba...

 

Regards,

Daniel He

 

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

Hi

 

Thank you for your answer.

Your measure work but i forgot to mention that i want to be able to create a slicer with the number of paiement code different to see which client have for example four paiement code. I think the best is a calculated column instead of a measure.

 

 

Hi @ThomasDaSilva,

could you please tell me if your problem has been solved? If it is, could you please mark the helpful replies as Answered?

 

Regards,

Daniel He

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

Hi @ThomasDaSilva,

Based on my test, you can refer to below steps:

1.You could create a calculated column.

Count = CALCULATE(COUNT(Table1[Paiement Code]),FILTER('Table1','Table1'[Code client]=EARLIER(Table1[Code client])))

 

2.Create a Table visual and add the related fields, now you can see the result.

1.PNG

You can also download the PBIX file to have a view.

https://www.dropbox.com/s/8zx0ingb8m6x51b/Count%20the%20number%20of%20value%20in%20one%20column%20ba...

 

Regards,

Daniel He

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

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.