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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
jthomson
Solution Sage
Solution Sage

Count instances of string in multiple columns

Hi,

 

Been searching the forums but can't find anything that exactly replicates what I'm trying to do - I currently have an Excel file that has the following column names (along with various others which I will want to slice on later, but doesn't affect this calculation) and some basic sample data:

 

Hire Request Date - Hirer 1 - Hirer 2 - Hirer 3 - Hirer 4

1/1/2017 - Bob - (blank) - (blank) - (blank)

1/1/2017 - Alice - Bob - (blank) - (blank)

2/1/2017 - (blank) - Bob - Clive - (blank)

3/1/2017 - Clive - (blank) - Bob - (blank)

 

The four hirer columns are populated either by a hirer name (of which there's around 20 possibilities which apply to every column, I have a separate table listing them all related to hirer 1 as active and the other hirer columns as inactive), or are blank, and more than one column can be non-blank at the same time in any given row. Very simply, I want to be able to count the total number of times each hirer appears in all the columns, so the expected results here would be Bob 4, Alice 1, Clive 2. In Excel this is just four countifs, but while I can get one column to work fine using counta (although it returns blanks as an option, which I don't want), if I try to add two or more of the columns together, it breaks down and provides wildly incorrect results. Any suggestions on how I can make progress on this?

1 ACCEPTED SOLUTION
Vvelarde
Community Champion
Community Champion

@jthomson

 

Hi try with this:

 

CountinAllHirerColumns =
CALCULATE (
    COUNTROWS ( Table1 ),
    USERELATIONSHIP ( HirerTable[Hirer], Table1[Hirer 1] )
)
    + CALCULATE (
        COUNTROWS ( Table1 ),
        USERELATIONSHIP ( HirerTable[Hirer], Table1[Hirer 2] )
    )
    + CALCULATE (
        COUNTROWS ( Table1 ),
        USERELATIONSHIP ( HirerTable[Hirer], Table1[Hirer 3] )
    )

After that in your visual filter:

 

img.png

 

Regards

 

Victor

Lima - Peru




Lima - Peru

View solution in original post

5 REPLIES 5
v-huizhn-msft
Microsoft Employee
Microsoft Employee

Hi @jthomson,

After research and test, the @Vvelarde solution is solid. Please folllow and mark the right reply as answer. And I am glad to help you if you still have any problems.

Best Regards,
Angelia

Vvelarde
Community Champion
Community Champion

@jthomson

 

Hi try with this:

 

CountinAllHirerColumns =
CALCULATE (
    COUNTROWS ( Table1 ),
    USERELATIONSHIP ( HirerTable[Hirer], Table1[Hirer 1] )
)
    + CALCULATE (
        COUNTROWS ( Table1 ),
        USERELATIONSHIP ( HirerTable[Hirer], Table1[Hirer 2] )
    )
    + CALCULATE (
        COUNTROWS ( Table1 ),
        USERELATIONSHIP ( HirerTable[Hirer], Table1[Hirer 3] )
    )

After that in your visual filter:

 

img.png

 

Regards

 

Victor

Lima - Peru




Lima - Peru
Anonymous
Not applicable

@Vvelarde 

Hi, adding to that, can this be used for dynamic number of Hirer columns in Table1?

Would you happen to have an idea what to do if there were 700+ Columns? In my case, I am looking for specific string in all these columns.
I can get the Results in excel by doing COUNTIF(A1:A700,"PASS") and it gives me the total count.
Please let me know if there is a solution to this. @Vvelarde 

 

Thanks in Advance

Hi,

In your text, you state 700+ columns but in your formula you have 700 rows.  Please clarify.  If there are 700 columns, you may have to Unpivot columns and then it becomes an easy one to solve.

Share some data and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.