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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
Microsoft Employee
Microsoft 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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.