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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.