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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
elakrz
Frequent Visitor

Count occurrences in a row

Here is my data base:

Name| 1st  | 2nd |  3rd |  4th | 5th

Ann   | five | five  | four | five | one

Tom  | four | one | four | five | four

 

and what I want to do is to create columns that would contain the number of occurrences in a row, so in this case what I want to achieve:

Name| 1st   | 2nd |  3rd |  4th | 5th  | Five | Four | One

Ann   | five  | five  | four | five | one |   3    |   1    | 1

Tom   | four | one | four | five | four |   1    |   3    | 1

 

How can I do that? 

3 REPLIES 3
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @elakrz,

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

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

L.PNG

2.Create three calculated columns.

Five = CALCULATE(COUNT('Table1 (2)'[Column2]),'Table1 (2)'[Column2]=5)+CALCULATE(COUNT('Table1 (2)'[Column3]),'Table1 (2)'[Column3]=5)+CALCULATE(COUNT('Table1 (2)'[Column4]),'Table1 (2)'[Column4]=5)+CALCULATE(COUNT('Table1 (2)'[Column5]),'Table1 (2)'[Column5]=5)+CALCULATE(COUNT('Table1 (2)'[Column6]),'Table1 (2)'[Column6]=5)

Four = CALCULATE(COUNT('Table1 (2)'[Column2]),'Table1 (2)'[Column2]=4)+CALCULATE(COUNT('Table1 (2)'[Column3]),'Table1 (2)'[Column3]=4)+CALCULATE(COUNT('Table1 (2)'[Column4]),'Table1 (2)'[Column4]=4)+CALCULATE(COUNT('Table1 (2)'[Column5]),'Table1 (2)'[Column5]=4)+CALCULATE(COUNT('Table1 (2)'[Column6]),'Table1 (2)'[Column6]=4)

Four = CALCULATE(COUNT('Table1 (2)'[Column2]),'Table1 (2)'[Column2]=1)+CALCULATE(COUNT('Table1 (2)'[Column3]),'Table1 (2)'[Column3]=1)+CALCULATE(COUNT('Table1 (2)'[Column4]),'Table1 (2)'[Column4]=1)+CALCULATE(COUNT('Table1 (2)'[Column5]),'Table1 (2)'[Column5]=1)+CALCULATE(COUNT('Table1 (2)'[Column6]),'Table1 (2)'[Column6]=1)

 

Now you can see the result.

LL.PNG

 

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

https://www.dropbox.com/s/0aqm5nnkro495go/Count%20occurrences%20in%20a%20row1.pbix?dl=0

 

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 @v-danhe-msft ,

 

I couldn't find anything like this for some time.

My tables are similair to @elakrz , only there need to be a lot of extra calculations after those, that were (as far as i could (not?) find) not possible without your help.

As counting text is doable, i still started just making a duplicate of the table, replaced the values to be counted, by numbers, (i.e. yes=1, no=2, n/a=3 (this can be easily renamed in visuals again))  and then used the formula. It works perfectly and my other calculations and measures are now perfectly alined.

 

It is a lot of work (i need to do about 20 tables and still counting, where there will be up to 20 counted columns per table) but it is worth while. Creating the calculation in a notepad like environment makes things a lot faster by bulk replacing things like tablename or culumn number/name.

 

Thanx!

I need to make it on string values and a lot of colums. So I was thinking of some functin, meassure or I don't know. 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors