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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
Employee
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

@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 AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.