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

How to count the occurrences of each value in a column, including repeated values.

Hi All,

 

I am very new to Power BI , and running with an issue. I am sure I will definitely get the solution to my issue here. 

Issue :

 

The below is a column I have

Col A

 

1

2

3

1

2

3

4

 

I need 

 

Col A          Occurance

1                   2

2                   2

3                   2

1                   2

2                   2

3                   2

4                   1

 

I want to count the occurrences of each value in a column , including the duplicates. 

 

Thanks a ton in advance.

 

Regards,

SKD

1 ACCEPTED SOLUTION
Eric_Zhang
Employee
Employee

@sukantdas

Add a calculated column.

 

Occurence = 
COUNTX (
    FILTER ( yourTable, EARLIER ( yourTable[Col A] ) = yourTable[Col A] ),
    yourTable[Col A]
)

 

Capture.PNG

View solution in original post

12 REPLIES 12
JofrainVisda
Advocate I
Advocate I

JofrainVisda_0-1707826641170.png

How about this. Count the occurence with parameters? like count the "Name" that is under the same Column 1 and Column 2?

Eric_Zhang
Employee
Employee

@sukantdas

Add a calculated column.

 

Occurence = 
COUNTX (
    FILTER ( yourTable, EARLIER ( yourTable[Col A] ) = yourTable[Col A] ),
    yourTable[Col A]
)

 

Capture.PNG

How can we do this for every related data in another column
ie
col A            colB               Occurence 
Mango         Unripe              2
Orange         Ripe                 1
Mango          Unripe             2 
Orange         Unripe             2
Mango         Ripe                 1
Orange        Unripe              2

So it counts based on two column conditions   

Hello, 

How do i make my calculated column to take into consideration the filters of my BI ? 

Thanks in advance,

Killian

Hi all,

 

Should there not be single quotes surrounding tableand column details? I couldnt get it to work without them.

 

Occurence = 
COUNTX (
    FILTER ( 'yourTable', EARLIER ( 'yourTable[Col A]' ) = 'yourTable[Col A]' ),
    'yourTable[Col A]'
)

 

Thanks.

 

Simon

Anonymous
Not applicable

THANK YOU, I have been searching all day and finnally your solution did the job!
@Eric_Zhang 

Hello,

 

Is there any way to do this on the M Query side of things?

Been looking for a solution, but my M Query is not so strong.

 

 

 

Cheers,

Niko

Hi there,

 

I've jus tried using your suggested solution to count the occurence of each userID in a column and have found the output appears to square each result. For example, where a userID appears twice in the column, the output in the occurrence column is 4 and where userID appears 6 times in the column the output in the occurrence column is 36. Any idea why this is happening? I really can't get my head around it I'm afriad!

 

Thanks for any help you can provide.

@Helen_R  Did you ever find a solution? I am having the same issue. 

In your visual, are you doing a count of the new field or a sum? If you do a sum, it will seem like the output is squared but the reality is you just have to change what the table/matrix is doing to the field. You could also probably do a max or min. Basically, just don't sum the values. 

I have a column like this 

 

mango

orange

mango

grape

orange

mango

orange

mango

apple

 

need an out put like 

mange 4

orange  3

Grape  1

Apple 1

Hi  @Eric_Zhang

 

 Thanks for the solution . It worked for me.  Can you please suggest where & how to increase knowledge in DAX.

 

Regards,

SKD

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.