Counting pairs in a table, excel - excel

I have a table consisting of character names in excel
Small section of table:
I'm looking to count the number of times a pair occurs in a row. eg the number of times yasuo and atroxx appear (3) or the amount of times zoe and zed appear (2) I've tried countifs() but that doesn't work and am looking for any suggestions

For long table it would be easier to solve the issue if you have Excel-365. Try below formula with Excel-365.
=SUM(MMULT(--(A2:E7="aatrox"),SEQUENCE(COLUMNS(A2:E2),,,0))*(MMULT(--(A2:E7="yasuo"),SEQUENCE(COLUMNS(A2:E2),,,0))))
For older versions of excel try-
=SUM(MMULT(--(A2:E7="aatrox"),TRANSPOSE({1,1,1,1,1}))*(MMULT(--(A2:E7="yasuo"),TRANSPOSE({1,1,1,1,1}))))

I think you can transform this question to 3 steps:
you count/countif wheather the name in each row;
you calculate weather the numbers of each target name appears are bigger than 1;
finally, sum the 0/1 result and you get the answer;

Related

Excel - Combine data from multiple tables dynamically

I would like to combine three different tables in Excel. I am struggling with the fact that the tables can vary in length.
For example:
What I would like to achieve is all the tables' data in one table without empty spaces. So first the two entries from the first table then the three entries from the second table and lastly the entry from the third table. But the amount of rows in each table can vary.
How can I do this dynamically so when the amount of entries in the tables change it can handle this? I'm using Mac with Office365. Thanks!
EDIT:
Output with Ron Rosenfeld's solution, the range of the list goes down from cell 5 - cell 103. Could this be reduced to 5 - 15?:
If you have Excel 2019 or Office 365, with the FILTERXML and TEXTJOIN functions, you can use:
=FILTERXML("<t><s>" & TEXTJOIN("</s><s>",TRUE,Table1,Table2, Table3) & "</s></t>","//s[.!=0]")
If those zero's are really blanks, you can omit [.!=0] from the xPath argument, but it won't hurt to leave it there
Edit:
With MAC versions of Office 365 that do not have the FILTERXML function, I believe the following will work:
=LET(
a,299,
x,IF(SEQUENCE(99,,0)=0,1,SEQUENCE(99,,0)*a),
y,TEXTJOIN(REPT(" ",a),TRUE,Table19,Table20,Table21),
z, TRIM(MID(y,x,a)),FILTER(z,(z<>"0")*(z<>""))
)
Note the a parameter in the above function
Because of how the splitting algorithm works, the sequence for each cell will not always start at the beginning of a string.
Hence, if there are enough letters in the various strings, the start number may eventually get offset enough to cause a split in the wrong location
One fix is to use an arbitrarily large number of space's to insert.
99 is frequently large enough, but not for this data set.
299 seems to be large enough for the data set as shown in your actual data.
I believe the minimum number should be the sum of the lengths of all the characters in the original tables (including the 0's) plus one (1). But not sure of this.
You can certainly adjust it as needed
If the number becomes too large, you could run into the 32,767 character limitation. If that happened, an error message would occur.
So, if you wanted to compute a, dynamically, you could try something like:
=LET(
a,SUM(LEN(Table19[Column1]),LEN(Table20[Column1]),LEN(Table21[Column1]))+1,
x,IF(SEQUENCE(99,,0)=0,1,SEQUENCE(99,,0)*a),
y,TEXTJOIN(REPT(" ",a),TRUE,Table19,Table20,Table21),
z, TRIM(MID(y,x,a)),FILTER(z,(z<>"0")*(z<>""))
)
but no guarantees.
Assuming the data is in A:C, and empty cell is blank (not 0).
In E1 put :
=IF(ROW()>COUNTA(A:C),"",
INDEX(A:C,
IF(ROW()<=COUNTA(A:A),ROW(),IF(ROW()<=COUNTA(A:B),ROW()-COUNTA(A:A),ROW()-COUNTA(A:B))),
IF(ROW()<=COUNTA(A:A),1,IF(ROW()<=COUNTA(A:B),2,3)))
)
Idea : use row() to guide in selection in index. counta() is used guide converting 'row()' to usable index numbers. Also make the output cell blank "" for row() > counta(a:c).
Please share if it works/not.

How do I recieve the number of cells based off of three columns in Excel?

I'm not too sure how to word this problem so, I apologize for the vagueness. Here is what I am trying to do though:
I have a large Excel table with a ton of values, I however, only care about 3 columns. The three columns I have are "Project Name", "Active/Planned", and "Week of Month". Here is an example of some values I would have:
Project Name
Active/Planned
Week of Month
StoreProj
Active
2021-07 Jul-Wk1
SecProj
Planned
2021-07 Jul-Wk2
StoreProj
Active
2021-07 Jul-Wk1
Now, I have used a formula to get the number of projects based on a specific week month and avoiding duplicate values for the project name. The code I used returns an integer of the number of projects. Here is what I used:
=IFERROR(ROWS(UNIQUE(FILTER(Table[Project Name],Table[Week of Month]=2021-07 Jul-Wk1))), 0)
This works as intended. Now the issue I am running into is that I need to filter through these rows as I did previously, but now I need to include the "Active/Planned" column. So, I want to be able to see how many projects I have based off of the week of the month and return a number of projects (excluding duplicate names), but be able to filter through that integer output based off of the active/planned projects. So in a perfect scenario I can choose the week of month and if the project is "Active" or "Planned" and see the amount of projects I have.
This might be an easy fix so I apologize, I am just stumped, any help would be greatly appreciated. Thanks!
Work through that step by step, you've got the FILTER function which is giving data to the UNIQUE function, to the ROWS function, and then your IFERROR. However, the data about whether each line/row is 'Active' or 'planned' isn't passed out beyond the FILTER function, so can't be used by anything further on in the above sequence.
Boring theoretical advice out the way, try this;
=COUNT(IF(UNIQUE(FILTER( Table[[Project Name]:[Active/Planned]], Table[Week of Month] = "2021-07 Jul-wk1"))= "Active", 1))
Explanation:
FILTER(...) outputs records with the relevant date filter, however it outputs Table[[Project Name]:[Active/Planned]] - both columns, to ensure all relevant data is there.
UNIQUE(...) Then narrows that down to unique values, although by this stage I'm not 100% sure you need this.
IF(... = "Active", 1) then replaces the 'Active' outputs with 1s
COUNT() returns the number of cells in the above that contain a number (the 1s from the IF())
Yes, you can't use COUNTIF on arrays (and all except that last bullet point above are outputting arrays not single values) - and no, I didn't know that before attempting to answer this question, found it over at a different question!

How to rank headers with Duplicate Values in Excel?

I would like to rank the headers of the columns based on the value of each row.
Apparently I can use the LARGE function, to get top values.
But the problem here is that I have duplicate values. And when I try to use INDEX-MATCH, it will return the same header multiple times. It will not fetch the second header of duplicate score.
Refer my desired output:
I tried the solution mentioned at:
https://www.exceltip.com/lookup-formulas/vlookup-top-5-values-with-duplicate-values-using-index-match-in-excel.html
but I do not want to include randomize function.
Thanks!
As mentioned in my comment, I added a fraction of the current column, so that the ranks are distinguishable by MATCH.
Note It's an array-formula which needs to be confirmed through CTRLSHIFTENTER
=INDEX($B1:$E1,MATCH(LARGE(($B2:$E2+COLUMN($B$2:$E$2)/100),COLUMN(A1)),$B2:$E2+COLUMN($B$2:$E$2)/100,0))
Depending on the number of ranks, you can add smaller fractions, so that the ranks don't increment.
About the question is to handle members of the same ranks. Two ways of handling indexes of the same values:
Place them in order in multiple cells.
Place them in order in one cell.
Excel functions can handle certain of them, such as sorting in ascending or descending order. But others, such as getting the sequence number of a value before sorting and getting the sequence numbers. Using esProc is much easy.
A
1 …(Data pasted from Excel)
2 =A1.split#n("\t")
3 =A2.(~.psort#z())
4 =A3.(["Self     Direction","Power","Universalism","Achievement"](~))
5 =A4.concat#n("\t")
For more explanation,see http://c.raqsoft.com/article/1610327593846
DISCLAIMER: This is about our tool esProc. It’s freemium.

What to use: COUNTIF or Vlookup or combined or else?

I got a big data file where I have to count how many events is per one serial number (in my case P/N) through more sheets (years). Those serials are in Column A (grey). On second picture is lookup table, so the data from where I have to search and Count events looking at (Column O - yellow) and Column A (artikel), using terms from Column P for all the sheets, I mean through different year. All sheets are consistent and looking exact the same.
What I tried to do is: COUNTIFS(A2:A142;VLOOKUP(A2;'Spareparts 2015'!$A$2:$O$164;15;FALSE))+COUNTIF('Spareparts 2015'!O2:O164;"Ersatz im Rahmen einer Wartung") to look for specific term but this is not what I wanted.
Idea is to get all these specific "terms" using P/N through all years (summed), to see how many times serial number (P/N) has been used through years. And I need total number (of 5 years). As you see in main table there are more serials, and everything what is needed is some good positioned function which I cant get...
Hopefully I was clear with my issue, it is a bit hard to explain, but I eager to provide more infos!
UPDATE!
This is actually what I wanted to accomplish (with Pivots is possible)
For every Serial (artikel) that I have in Calculated sheet, I wanna look and count all instances (Grund fur ersatz in Column O) through years and different sheets. Every sheet has mixed serials, and these occurrences, so I have to couple them with main table and to count total number of them, how many times something from Column O appeared in some of Serials through 5 years.
One option is using Pivot tables actually, but I wanted to know how I can solve it with formulas also.
EDIT #2
Given that the relationship between each serial number and the look up term is 'Many to Many' but not 'One to One', one way to count the occurrence of each term for each serial number is to
Firstly put all 5 years of data into one big table, and name the following ranges:
Name_All being names in Column O of the master data table;
SN_All being serial numbers in Column A of the master data table.
Secondly, create a look up sheet to list all serial numbers and associated look up terms as shown below:
Then you can use COUNTIFS to count the occurrence for each term per serial number:
=COUNTIFS(SN_All,A2,Name_All,B2)
See following screen-shot for more clarifications.
A better/quicker approach would be using pivot table as being mentioned by OP.

Excel functions: indirect address column

First time asking a question after reading a lot in the past.
I'm running the following array function excel:
INDEX('Available Options'!$A$1:$CM$137,$B$1,
SMALL(
IF(
INDIRECT("'Feasibility Options'!"&ADDRESS($B$1,COLUMN('Feasibility Options'!$G$1),1,1)&":"&ADDRESS($B$1,COLUMN('Feasibility Options'!$O$1),1,1))=2,
COLUMN(INDIRECT("'Feasibility Options'!"&ADDRESS($B$1,COLUMN('Feasibility Options'!$G$1),1,1)&":"&ADDRESS($B$1,COLUMN('Feasibility Options'!$O$1),1,1)))),
ROW('Available Options'!1:1)))
The idea behind this is that there are a number of cells which either have 1s, 2s or 3s in (1 means default, 2 means an alternative and 3 means inactive) in a separate tab called 'Feasibility Options', and the prices for these options are held in the 'Available Options' tab. $B$1 contains a row number produced through a separate calculation.
Evaluating this formula gives a value error when resolving the Indirect part of the function, but the function works if I replace the column number formulae with column numbers as below:
INDEX('Available Options'!$A$1:$CM$137,$B$1,
SMALL(
IF(INDIRECT("'Feasibility Options'!"&ADDRESS($B$1,7,1,1)&":"&ADDRESS($B$1,15,1,1))=2,COLUMN(INDIRECT("'Feasibility Options'!"&ADDRESS($B$1,7,1,1)&":"&ADDRESS($B$1,15,1,1)))),ROW('Available Options'!1:1)))
Could someone explain why this would happen and how to fix it? I ideally need to use cell references rather than hardcoded column numbers as I will likely need to add more columns in at a later date.
Thanks for any help you can give and apologies if I've missed a previous thread which answers this sort of question.
I haven't tested this but I suspect the problem is caused by the COLUMN function which returns an array (even for a single value) and sometimes Excel has trouble processing this:
You can normally make it work by wrapping COLUMN in a SUM or MAX function, e.g.
MAX(COLUMN('Feasibility Options'!$G$1))
or using COLUMNS function instead, something like
COLUMNS('Feasibility Options'!$G$1:G1)
which can be dragged to increment
Better still would be to replace the whole INDIRECT/ADDRESS parts with INDEX, which should be simpler, shorter and more efficient. I can give you more detail on that if you're interested

Resources