Excel: Frequency of variables using countif with & - excel

I have two excel sheets. I am finding the frequency of variable school IDs from sheet 1 into sheet2. Lets say a student volunteers for some activity at two schools. So there is an &. I want countif to count schools even where there is &
sheet1
A B
1 Student name School ID
2 S1 Sch333 & Sch209
3 S2 Sch209
4 S3 Sch333
5 S4 Sch209 & Sch111
6 S5 Sch209
sheet2
A B
1 School ID Frequency
2 Sch209
3 Sch333
4 Sch111
Formula for frequency of school IDs in cell B2 of sheet2
=COUNTIFS('sheet1'!$b:$b,'sheet2'!a2)
This ignores the rows where there is &. Expected output
A B
1 School ID Frequency
2 Sch209 4
3 Sch333 2
4 Sch111 1

You can sum the counts for the value alone plus before or after " & "

Maybe,
In sheet2, B2 array (CSE) formula copied down :
=COUNT(SEARCH(A2,'sheet1'!$B$2:$B$100))
Remark : Array (CSE) formula to be confirmed by "Ctrl"+"Shift"+"Enter" to enter it.

According to #shrivallabha.redij, you can remplace your formula
=COUNTIFS('sheet1'!$b:$b,'sheet2'!a2)
by this one:
=COUNTIFS('sheet1'!$b:$b,"*" & 'Sheet2'!a2 & "*")

Related

Find matches of 2 items in 2 different columns

Hello good afternoon community. I have an Excel question
I have this table
enter image description here
I can't find a way to determine which is the combination that is repeated the most but in both directions.
I mean, with the function count.si.set I can count how many Italy vs Portugal there were (12) but it doesn't give me how many Italy vs Portugal + Portugal vs Italy there were (14)
What is the step that I am missing?
You can use the greater than operator to check which word comes first alphabetically. Eg, IF(A1>A2,1,0) will return a 1 if the word in Cell A2 is alphabetically Earlier than the word in Cell A1.
Use this in the "Enfrentamientos" column with the following formula:
IF(A1 < B1, A1 & " " & " " B1, B1 & " " & A1)
This cells output will be the words in A1 and B1 concatenated in alphabetical order, so your Argentina & Germany pairs will come out the same as your Germany & Argentina Pairs.
Copy that formula down to the lower rows so it applies to each pair
Hope this helped!

Compare 6 columns and return non identical value

I think I need a macro for what I would like to accomplish. I have 3 columns on sheet 1 and 2, but I would like to compare them and return a list under sheet 3 that has no duplicates and keeps track of the changes.
Sheet1 (New):
Count State City
1 MO STL
2 MO STP
1 FL Tampa
1 FL Ft. L
Sheet2 (Old):
Count State City
7 MO STL
6 MO STP
5 FL Tampa
4 TX Hston
Sheet3:
State City CountNew CountOld
MO STL 1 7
MO STP 2 6
FL Tampa 1 5
FL Ft.L 1
TX Hston 4
So far what I have accomplished has not help me and I cant find any other case with a situation like this one. I was trying to do this through formulas, but quickly realized thatall I was able to do was transfer the values of the columns from sheet 1 and 2, to sheet 3. But I was not able to accommodate the cell values that differ (Houston and Fort Lauderdale).
Would appreciate any help.
Thanks!
An idea would be something along these lines for finding uniques with a State & City helper column or add more to check the 2 columns?
In sheet1 and sheet 2 have a = State & "_" & City
In Sheet 3, A1 you can have =Sheet1!A1
and in A2 you can have =Sheet2!A1
then filled down from A3, you can have the following array formula
=IFERROR(IFERROR(INDEX(Sheet1!$A2:$A$10,MATCH(0,COUNTIF(Sheet3!$A$1:$A2,Sheet1!$A2:$A$10),0),1),INDEX(Sheet2!$A2:$A$10,MATCH(0,COUNTIF(Sheet3!$A$1:$A2,Sheet2!$A2:$A$10),0),1)),"")
This will give you the uniques across the 2 tabs, for normal lookups off the unique helper columns

Reference cells from column a where column b is atleast (value)

I am looking for a formula that can get me the reference of cells in "Column A" if "Column B" >= 2.
i.e.
Column A Column B
Company 1 1
Company 2 1
Company 3 3
Company 4 1
Company 5 5
Company 6 4
So in this example the output would be
Column A
Company 3
Company 5
Company 6
I am a bit confused on how to approach this, can you guide me in the right direction?
Both these answers use an array formula, so enter with Ctrl+Shift+Enter in first cell and drag down.
If your list starts on row 1 you can use:
{=IFERROR(INDEX($A$1:$A$6,SMALL(IF($B$1:$B$6>=2,ROW($B$1:$B$6),""),ROW(B1))),"")}
Otherwise use (this is for rows 10:15):
{=IFERROR(INDEX($A$10:$A$15,SMALL(IF($B$10:$B$15>=2,ROW($B$10:$B$15)-MIN(ROW($B$10:$B$15))+1,""),ROW(B1))),"")}

Excel extract unique objects from list

I have a large list of companies who collaborate with my company. My company is broken down into different research groups. A company might collaborate with a single research group multiple times on the list or with multiple research groups.
I would like to find out which companies only collaborate with a single research group. Example of data is below, you can see that company A only collaborates with group 1 but multiple times, but company B collabs with many groups. How can I count this?
Examples data:
Group Company
1 A
1 B
1 C
1 A
1 C
2 D
2 D
2 E
2 E
2 B
2 D
3 D
3 F
3 B
3 F
4 G
4 B
4 B
It would be a binary result, 1=company is unique to group, 0=company is not unique to group.
An extension to this (although not included in my question) would be, how many groups do companies collab with on average
There's a workaround for what you want to achieve. Following solution use couple of helper columns and at the end will give result whether company is unique to group or not and count of groups companies collaborate with.
Assuming your data Group and Company are in Column A and Column B respectively follow the following steps:
Step 1: Get unique combination of Group and Company
In Cell D2 enter the following formula and drag/copy down as required.
=IFERROR(INDEX($A$2:$A$19 & "," & $B$2:$B$19,MATCH(0,INDEX(COUNTIF($D$1:D1,$A$2:$A$19 & "," & $B$2:$B$19),0,0),0)),"")
Step 2: Get count of each combination in data
In Cell E2 enter the following formula and drag/copy down till the row where Column D display values.
=COUNTIFS($A$2:$A$19,LEFT(D2,(FIND(",",D2,1)-1)),$B$2:$B$19,MID(D2,FIND(",",D2)+1,256))
This formula will give the count of occurrence of each combination from Column D in your data. For example, Group 1 and Company A occurs two time in you data, Group 2 and Company D occurs 3 times in your data, and so on.
Step 3: Get list of unique companies from Column B
In Cell F2 enter the following formula and drag/copy down as required.
=IFERROR(INDEX($B$2:$B$14,MATCH(0,INDEX(COUNTIF($F$1:F1,$B$2:$B$14),0,0),0)),"")
Step 4: Get count of groups each company collaborate with
In Cell G2 enter the following formula and drag/copy down till the row where Column F display values.
=COUNT(IF(MID($D$2:$D$12,FIND(",",$D$2:$D$12)+1,256)=F2,$E$2:$E$12))
This is an array formula so commit it by pressing Ctrl+Shift+Enter
Step 5: Check whether company is unique to Group or not
In Cell H2 enter the following formula and drag/copy down till the row where Column G display values.
=IF(COUNT(IF(MID($D$2:$D$12,FIND(",",$D$2:$D$12)+1,256)=F2,$E$2:$E$12))=1,1,0)
Again, this is an array formula so commit it by pressing Ctrl+Shift+Enter
or instead use this formula =IF(G2=1,1,0)
EDIT : As per requirement mentioned in comment
In Cell J2 enter:
=IFERROR(INDEX($B$2:$B$19 & "," & $A$2:$A$19,MATCH(0,INDEX(COUNTIF($D$1:J1,$A$2:$A$19 & "," & $B$2:$B$19),0,0),0)),"")
In Cell K2 enter:
=COUNTIFS($A$2:$A$19,MID(J2,FIND(",",J2)+1,256),$B$2:$B$19,LEFT(J2,(FIND(",",J2,1)-1)))
In Cell L2 enter:
=IFERROR(INDEX($A$2:$A$19,MATCH(0,INDEX(COUNTIF($L$1:L1,$A$2:$A$19),0,0),0)),"")
In Cell M2 enter:
=COUNT(IF(VALUE(MID($J$2:$J$12,FIND(",",$J$2:$J$12)+1,256))=L2,$E$2:$E$12))
This is an array formula.
In Cell N2 enter:
=IF(N2=1,1,0)
or
=IF(COUNT(IF(VALUE(MID($J$2:$J$12,FIND(",",$J$2:$J$12)+1,256))=L2,$E$2:$E$12))=1,1,0)
This formula is also an array formula.
See image for reference:

Simple excel adding two cells and displaying alphabetically

This seems like an incredibly simple problem but I can not figure out how to solve it.
I am trying create a new column with pair of place names in from an excel sheet, a simplified version of which is shown below.
Sheet 1:
| A
1 Dunfermline
2 Torryburn
3 Burntisland
4 Kinghorn
5 Torryburn
6 Carnock
I would like to pull out into B1, B3, B5 et. the pairs of places. I have managed to do this using
=A2 & "-" & A3
but I would like the place name that begins with the letter earliest in the alphabet to be displayed first, as below. My method does not work in the case of B5 - I can only return 'Torryburn - Carnock'
Desired Output:
| A | B
1 Dunfermline Dunfermline - Torryburn
2 Torryburn
3 Burntisland Burntisland - Kinghorn
4 Kinghorn
5 Torryburn Carnock - Torryburn
6 Carnock
Is there a method of sorting the cells and adding them together as required?
<> does the trick:
=IF(A2<A3,A2,A3) & "-" & IF(A2>A3,A2,A3)
You can always use the IF function (or IIF, depending on your version of Excel) to check if A2 < A3, and then show the appropriate reuslts. For example:
=IF(A2 < A3, A2 & "-" & A3, A3 & "-" & A2)

Resources