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
Anonymous
Not applicable

Count number of rows in different table by specific filters

Hi all,

I am quite new in powerbi and I am struggling with a task and I hope you can give me some good pointers.

 

I have two tables and I would like to add custom columns in table 1 for specific rowcounts (based on filters) I need to count in table 2.

Table1 - OpenOpps

- Unique list of opportunities - no duplicates

opp-idopp-nameopp-value
1abc10000
2xyz5000
3test17000
4test28000

 

Table2 - OpenOppsWithContactTypes

- List of opportunities with assigned contact types (1 opportunity can have multiple contact types) -  duplicate columns with contact type as unique field

- The different contact types are for example SalesContactType1 / SalesContactType2 / TechnicalContactType1 / TechnicalContactType2 / ...

opp-idopp-nameopp-valueContactRole
1abc10000SalesContactType1
1abc10000TechnicalContactType1
2xyz5000TechnicalContactType1
2xyz5000TechnicalContactType2
3test17000SalesContactType1
3test17000SalesContactType2
3test17000SalesContactType3
4test28000OtherContactType1



 

Table1 is linked to table2 with a 1-many relationship on the field opp-id

 

What am I trying to achieve:

- Custom column "SalesContactType" to be added in table1 - count of all different SalesContactTypes for that specific opportunity

- Custom column "TechnicalContactType" to be added in table1 - count of all different TechnicalContactTypes for that specific opportunity

- Custom column "OtherContactType" to be added in table1 - count of all different OtherContactTypes for that specific opportunity

 

opp-idopp-nameopp-valueSalesContactTypeTechnicalContactTypeOtherContactType1
1abc10000110
2xyz5000020
3test17000300
4test28000001

 

What I tried was something like this which provided me a number of all these entries in the table and not per opportunity. And it also only worked for one filter where I need to filter on multiple ones.

Column = COUNTROWS(FILTER('OpenOppsWithContactTypes', 'OpenOppsWithContactTypes'[Contact Role]="SalesContactType"))
 

Anyone has a good idea or suggestion?

 

Thanks.

DB

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hello,

 

In power Query Editor, perform the "split column" By Non-Digit to Digit operation on the column "ContactRole" of Table2. then rename that column as "ContactRole".


Then create 3 measure like this in report,

 

SalesContactRole = CALCULATE(COUNT(AllOppsWithContactRoles[ContactRole]),FILTER(AllOppsWithContactRoles,(AllOppsWithContactRoles[ContactRole]="SalesContactRole")))+0
 

TechnicalContactRole = CALCULATE(COUNT(AllOppsWithContactRoles[ContactRole]),FILTER(AllOppsWithContactRoles,(AllOppsWithContactRoles[ContactRole]="TechnicalContactRole")))+0
 
OtherContactRole = CALCULATE(COUNT(AllOppsWithContactRoles[ContactRole]),FILTER(AllOppsWithContactRoles,(AllOppsWithContactRoles[ContactRole]="OtherContactRole")))+0
 
you will get the final result.
 
let me know if you need pbix file for the same.

View solution in original post

2 REPLIES 2
Vera_33
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

Another way: Split the column in DAX, SalesContactType1 does not equal to SalesContactType...use the new columns to count rows

 

Vera_33_0-1614926628878.png

Type = LEFT([ContactRole],LEN([ContactRole])-1)

TypeNumber = RIGHT([ContactRole],1)

 

Anonymous
Not applicable

Hello,

 

In power Query Editor, perform the "split column" By Non-Digit to Digit operation on the column "ContactRole" of Table2. then rename that column as "ContactRole".


Then create 3 measure like this in report,

 

SalesContactRole = CALCULATE(COUNT(AllOppsWithContactRoles[ContactRole]),FILTER(AllOppsWithContactRoles,(AllOppsWithContactRoles[ContactRole]="SalesContactRole")))+0
 

TechnicalContactRole = CALCULATE(COUNT(AllOppsWithContactRoles[ContactRole]),FILTER(AllOppsWithContactRoles,(AllOppsWithContactRoles[ContactRole]="TechnicalContactRole")))+0
 
OtherContactRole = CALCULATE(COUNT(AllOppsWithContactRoles[ContactRole]),FILTER(AllOppsWithContactRoles,(AllOppsWithContactRoles[ContactRole]="OtherContactRole")))+0
 
you will get the final result.
 
let me know if you need pbix file for the same.

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