Excel multiple criteria by row - excel

I am having trouble with Excel. I have a data set containing bibliography. For each row I have each author from a specific title, separated by columns. I wanted to make an association between authors to see which have publications together and how many times.
Example of data set:
full view
Output wanted:
full view
I have approximately 43 columns by 500 rows. I've already tried COUNTIFS and SUMPRODUCT but both don't give me the output that I want.
Thank you for your help :)

There may be an easier way than this, but with 43 columns (a lot of co-authors?) I can only think of using an array formula, so the method is:-
(1) Get row totals of original data for first author
(2) Get row totals of second author
(3) Multiply them together to get rows (publications) where both authors occur.
(4) Optional - check that each row total is greater than zero -shouldn't be necessary unless author's name is repeated.
(5) Add them all up.
=SUM(--(MMULT(N($A$2:$D$20=G$1),TRANSPOSE(COLUMN($A$1:$D$1))^0)*MMULT(N($A$2:$D$20=$F2),TRANSPOSE(COLUMN($A$1:$D$1))^0)>0))
Must be entered as an array formula using CtrlShiftEnter.
I have just used initials to demonstrate the method.
I have formatted them using "#" to make the zeroes appear as blanks.

Related

How to count similar groups of elements in Excel using multiple criteria?

I am trying to count groupings of elements in a list, in Excel, with groupings defined by 2 conditions: same Element and same Group code, as shown in the image below. The column C formula seems to throw errors as shown in orange highlighting in cells C9-C11. The formula for column C is displayed starting in column D. My expected grouping count is shown in column L with explanation starting in column M. Cells L9-L12 show what I expect the element count to be for Element X/Group 0.
Is there a correct formula for counting multiple-criteria groupings in Excel 365? I have tried various iterations of countifs() and sumproduct (See column D of the screencap) with no luck yet.
Post possible solution:
Now showing a scenario where the solution doesn't hold up (holds up in all other 16 scenarios I ran but not this one ???), see the orange cells with strange output versus expected output in yellow:
OK well in the first iteration of your question what seemed like a long time ago we all assumed that you wanted to count the total number of unique groups you have got so far. Now it's looking a bit different - the example implies that if both the element and group are repeated later on you want to revert back to the count of that element and group only and not the total count. I think what you want is a match like this:
=MATCH(A4&B4,SORT(UNIQUE(FILTER(A$4:A4&B$4:B4,A$4:A4<>""))),0)-
MATCH(A4&"*",SORT(UNIQUE(FILTER(A$4:A4&B$4:B4,A$4:A4<>""))),0)+1
Could be simplified using Let but it's late here and it's tentative anyway.
However the sorting assumes that the group keeps on increasing within each element and that wasn't the case in the first iteration of your question. You could try Sortby just sorting on the Element but that will have to wait till tomorrow.
EDIT
Here is my revised formula - plz try it.
=LET(range,A4:B$4,
unique,UNIQUE(range),
uniqueElement,INDEX(unique,0,1),
sortby,SORTBY(unique,uniqueElement,1),
sortElement,INDEX(sortby,0,1),
sortGroup,INDEX(sortby,0,2),
MATCH(1,(sortElement=A4)*(sortGroup=B4),0)
-MATCH(A4,sortElement,0)+1)
You could also use Take instead of Index. I've removed the filter for clarity because there aren't any blanks in the test data.

Getting number and off setting numbers from array in Excel

I have array of numbers in a single column like this:
I want only that numbers for which corresponding negative numbers exist. If number exist 2 times, but negative number exist only one time, then I wanted to retain one positive and one negative number. Similarly, if number exists 3 times, and negative number appears only two times, then I want 2 set of numbers including positive and negative. In this case, I wanted to get output:
5 2 -2 -5
Orders of numbers are not relevant for me. Please do not use VBA. You can create multiple column and apply filter at the end.
Thank you for the response, but I wanted to get the data in column next to the values. Like:
5
2
-2
-5
Please help.
Here's another Office 365 solution:
Name the data range DATA
Put this formula anywhere: =CONCAT(REPT(-ROW(A1:A100)&" "&ROW(A1:A100)&" ",COUNTIF(DATA,"="&ROW(A1:A100)*IF(COUNTIF(DATA,"="&-ROW(A1:A100))<COUNTIF(DATA,"="&ROW(A1:A100)),-1,1))))
That will output the pairs into one cell.
Here's a slightly modified Step 2, which excludes duplicates: =CONCAT(IF((COUNTIF(DATA,"="&-ROW(A1:A100))>0)*(COUNTIF(DATA,"="&ROW(A1:A100))>0),-ROW(A1:A100)&" "&ROW(A1:A100)&" ",""))
Looks like this:
The data doesn't need to be sorted. Both methods work up to 100, but you can easily expand that by changing A100 to A1000 or whatever you need.
Use the vlookup formula to identify the rows, and you can use the Filter & Unique formula to get the list, or a pivot table.
First, immediately next to your data use the formula:
=vlookup(A1*-1,$A$1:$A$1,1,0)
For non-365:
This will produce an error for each instance that doesn't have a match. You can filter at this point to get your list from the existing table. You can also create a pivot table under the Data tab of your ribbon and inserting a pivot table. Filter the #N/A from there to get an exclusive list without hidden rows.
For 365:
You can use the following combination of formulas to get the exclusive list as well.
=UNIQUE(FILTER(B1:B8,ISNUMBER(B1:B8)),0,0) or =UNIQUE(FILTER($B$1:$B$8,ISNUMBER($B$1:$B$8)),0,0) should yield the same results
As ScottCraner mentioned, you can circumvent the helper column in 365 by modifying the formula a bit more:
=UNIQUE(FILTER(A1:A8,ISNUMBER(MATCH(-A1:A8,A1:A8,0)),"")
The Match here is doing something similar to the Vlookup, but housing that logic within the formula, so it's a cleaner solution in my opinion.
Using your data the result was { -5,-2,2,5 }
These are spill formulas so you only need to put it in one spot and it will expand the formula over the adjacent cells below where it's entered for however many cells needed to list all the unique numbers that occur. It takes into account the negatives and so on. This may be a 365 formula, so if you're on another version of excel it may not work.
Edit: Adjusted the instructions to fully address the question.

Transfer Excel row data into its relevant columns

I've lost days to this problem.
To solve this issue I have amassed 6 sheets of different data with different attempts. I've tried offsets, dynamic ranges, vlookups, counts, countifs, left, right, row, everything. I can't get around it.
What I want to do is transpose data in the following format:
Into its correspondingly named four columns to reach the desired outcome:
Inconsistency of each individual product's data is the issue. Product 9 has two product options and two prices, whilst the tenth product has no description and no options.
I also have the original data in the following format if it is of use.
Any help or resources greatly appreciated.
I have gotten by with excel for the past few years without learning VBA, therefore a formula approach is most welcome. Though, if necessary, I am not massively intimidated by learning the language if needs be as I am a novice in CSS and HTML and dabbled in a couple of programming languages.
Edit 1 - A more concise way of viewing the issue is contained in this image where the data is on the left and the outcome is on the right.
Edit 2 - This is a link to a google sheet subject to request in the comments below. I have included all relevant information and some other stuff.
EDIT: you've added clarification since I put this together. I'll leave it in, because it is a partial solution and may lead you/someone to a full one.
(it supplies only 1 result if there are multiple matches for a particular product and information type, but handles missing information).
I have a solution. In your second example of the input (product #, type and information columns across the top), insert a new column between B and C. In the first data row of that new column, combine the text from the product # and 'Type' columns, i.e
C2 = A2 & "," & B2
Result of C2 should be "Product 1,Product Name"
Then for your transposed results table, all you need is a valid list of product #'s, and you can use a simple vlookup on C and D columns. You just have to construct a matching search term that combines the required product # with the type you are looking for.
The formula in H2 below is constructed so that you can drag it across and down as necessary.
You'll get N/A for anything that doesn't have an entry, and you'll get whatever vlookup usually does if it finds duplicate matches.

Want to index/match just the unique row

I have a sheet with multiple parts belonging to different affiliates and areas. I want to write a formula that brings up the unique part from this list. I created a formula for the data set to get the row number of each unique part as shown below:
I want to just pull the rows from G which began with a 1. I try using the formula below, but it just will pull all the rows in column A:
INDEX(DATA!$A:$A,MATCH(1&"-"&$A$2&"-"&DATA!A2,DATA!G:G,0))
And produce this result:
01949765
01949765
04581664AA
04581664AA
04581914AC
04581914AC
04581914AC
04581914AD
04581915AB
Below is what I want to see:
01949765
04581664AA
04581914AC
04581914AD
04581915AB
Any formula I can use to get just the unique values?
As I understand it, the row already split the unique values, you just have to pull anything in A that has a G counterpart starting with 1.
=INDEX($A$1:$A$8,AGGREGATE(15,6,((LEFT($B$1:$B$8,1)="1")*1/(LEFT($B$1:$B$8,1)="1")*1)*ROW(INDIRECT("1:"&COUNTA($B$1:$B$8))),ROW()-10))
You'll have to adapt the different ranges to your data and the "-10" at the end depending on where you put your result.
My proposal, add a column, put in
=COUNTIF($A$2:$A2,A2)
Then filter only the value = 1. You'll see the results straightaway..
about the parts name in G..
you can load it using index()+match() function. Eg =INDEX(G:G,MATCH(A2,A:A,0)) to 'load' it.
Hope it helps.

Sumproduct or Countif on a 2D matrix

I'm working on data from a population of people with allergies. Each person has a unique ExceptionID, and each allergen has a unique AllergenID (451 in total).
I have a data table with 2 columns (ExceptionID and AllergenID), where each person's allergies are listed row by row. This means that the ExceptionID column has repeated values for people with multiple allergies, and the AllergenID column has repeated values for the different people who have that allergy.
I am trying to count how many times each pair of allergies is present in this population (e.g. Allergen#107 & Allergen#108, Allergen#107 & Allergen#109,etc). To keep it simple I've created a matrix of 451 rows X 451 columns, representing every pair (twice actually because A/B and B/A are equivalent).
I somehow need to use the row name (allergenID) to lookup the ExceptionID in my data table, and count the cases where that matches the ExceptionIDs from the column name (also AllergenID). I have no problem using Vlookup or Index/Match, but I'm struggling with the correct combination of a lookup and Sumproduct or Countif formula.
Any help is greatly appreciated!
Mike
PS I'm using Excel 2016 if that changes anything.
-=UPDATE=-
So the methods suggested by Dirk and MacroMarc both worked, though I couldn't apply the latter to my full data set (17,000+ rows) because it was taking a long time.
I've since decided to turn this into a VBA macro because we now want to see the counts of triplets instead of pairs.
With the 2 columns you start with, it is as good as impossible... You would need to check every ExceptionID to have 2 different specific AllergenID. Better use a helper-table with ExceptionID as rows and AllergenID as columns (or the opposite... whatever you like). The helper table needs a formula like:
=COUNTIFS($A:$A,$D2,$B:$B,E$1)
Which then can be auto-filled. (The ranges are from my example, you need to change them to your needs).
With this helper-matrix you can easily go for your bigger matrix like this:
=COUNTIFS(E:E,1,INDEX($E:$G,,MATCH($I2,$E$1:$G$1,0)),1)
Again, you can auto-fill with this formula, but you need to change it, so it fits your needs.
Because the columns have the same ID2 (would be your AllergenID), there is no need to lookup them because E:E changes automatically with the auto-fill.
Most important part of the formulas are the $ which should not be messed up, or you can not auto-fill it.
Picture of my self-made example (formulas are from the upper left cell in each table):
If you still have any questions, just ask :)
It can be done straight from your original set-up with array formulas:
Please note that array formulas MUST be entered with Ctrl-Shift-Enter, before copying across and down:
In the example pic, I have NAMED the data ranges $A$2:$A$21 as 'People' and $B$2:$B$21 as 'Allergens' to make it a nicer set-up. You can see in the formula bar how that looks as a formula. However you could use the standard references like this in your first matrix cell:
EDIT: silly me, N function is not needed to turn the booleans into 1's and 0's, since multiplying booleans will do the trick. Below formula works...
SUM(IF(MATCH($A$2:$A$21,$A$2:$A$21,0)=ROW($A$2:$A$21)-1, NOT(ISERROR(MATCH($A$2:$A$21&$E2,$A$2:$A$21&$B$2:$B$21,0)))*NOT(ISERROR(MATCH($A$2:$A$21&F$1, $A$2:$A$21&$B$2:$B$21,0))), 0))
Then copy from F2 across and down. It can be perhaps improved in technique with sumproduct or whatever, but it's just a rough example of the technique....

Resources