Lets say I have two sets of data and want to compare each row and column to make sure that they are identical.
Both sets of data have the same number of Columns and rows, say first set is Columns A-G, 2nd set of data is on the same tab an goes from H-N (in reality I actually have 50+ columns in each set).
Typically what I do when I don't have a lot of columns, i do something like:
=if(AND(A2 = h2, B2=i2, c2=j2),"Good","Bad")
Once I have a formula, then I press the little square and drag it down across all rows. This is able to quickly show me whether there is data difference in any of the columns or not.
However in this case I have a lot of columns to compare. Is there a quicker way to do this, or generate dynamically somehow?
Thanks.
You could use SUMPRODUCT:
=IF(SUMPRODUCT(--(A2:G2=H2:N2))=0,"Good","Bad")
=TEXTJOIN(,,A1:C1)=TEXTJOIN(,,h1:j1)
This will return either TRUE or FALSE.
Related
The situation: I have an automatic procedure for gathering data from different input-sheets and presenting in a pivot-friendly format. It appears others are in need of the same data, though they want it formatted slightly differently (and they are not friends with excel). I therefor have a version of my table formatted as they want it (with empty columns where my extract does not contain any data).
The table (both) is one line for each department for each year for each cost/income (from now, cost) category. The raw data contains the cost for each year, though some of the users want it to be cost delta from initial year. I want:
One column for raw cost (X). One column for delta cost (Y). One output column (Z) that contains one of those two values, depending on dropdown selection. The first two columns are situated to the right of the "select with mouse and copy these"-columns, so that I dont need to teach the other users how to select non-adjecent columns :P (just letting u know the level of understanding i have to work with here)
Now the naive approach to this would be to have an if-statement in column Z like this:
=IF(selected_Calc="Use raw cost";[#[X]];[#[Y]])
Alternatively nest more ifs (one for "Use difference to 2019", and potentially add more nesting if more ways to show the value should appear in future)
This works. However, it isnt as elegant as I would like it, and if I indeed end up with more ways to calculate this for other people, it will be a lot of nested ifs.
I was therefore considering something like this:
=INDIRECT("[#["INDEX(mapTab_out;match(selected_Calc;mapTab_in;0))&]]")
But this gives a #ref, and tbh i didn't really expect it to work.
The idea is though: .
Have a range mapTab_in. This has the different selections for the dropdown box.
Have the adjecent range mapTab_out. This has the name of the column (X,Y...) that contains the desired calculation)
Have in column Z a formula for selecting which column's (X,Y...) value is to be displayed in Z
The google-stuff I have found so far all seem interested in using the indirect function from outside the table, and usually want to sum an entire column. I have used this in the past. The "ThisRow" things like using # dont seem to work with indirect though. Any ideas, or have I simply made some beginner-error in my formula?
Assuming it's in the same table, you can take advantage of implicit intersection and simply use:
=INDEX(Tablename,,MATCH(selected_Calc,Tablename[#Headers],0))
where selected_Calc is the name of the column you want back. (You could make that the result of a further INDEX/MATCH if you want to use a lookup table for some reason.)
This is what I'm trying to do. There are two columns. The first one contains the drawing number of a P&ID and The other one contains the IO type. Columns B and N respectively. I want the number of DOs for the drawing number ZCPL-P2179-B1-101. I know a simple COUNTIF function works but it is inefficient since rows keep expanding and it is quite tedious to constantly reselect the ranges.
Why dont you use Simple Countif with whole column as a Range
=COUNTIFS(B:B;"B1";C:C;"C1")
Just drag this formula in the whole column, even if your data is increasing you just have to click once to drag the formula.
Later take out Unique of P&ID number and Dos to find the distinct count.
I hope this helps
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....
I've had a look around and can't find a solution, and I don't even know if this is possible.
I have two worksheets. I would like Sheet1!G5 to display the sum of values in Sheet2!D:D where Sheet2!A:A OR Sheet2!B:B is equal to Sheet1!D5.
I know its a bit complex, and like I say I don't even know if it is possible, or if SUMIFS is the correct formula to be using.
see images below for dummy data in the spreadsheets..
basically I want someone to be able to search how many Desktop or how many HP Elitedesk 800 G1 there are (there are more different models of desktops, laptops and monitors etc, but I just don't have them in the dummy data...that's why I want to be able to search both fields.
If my logic is correct you should be able to get away with two separate SUMIF's, one for column A and one for column B, added together:-
=SUMIF(Sheet2!A:A,D5,Sheet2!D:D)+SUMIF(Sheet2!B:B,D5,Sheet2!D:D)
It doesn't look as if it's possible to have the same thing in column A and B for any row, but if so you could make a correction to avoid double-counting as follows:-
=SUMIF(Sheet2!A:A,D5,Sheet2!D:D)+SUMIF(Sheet2!B:B,D5,Sheet2!D:D)-SUMIFS(Sheet2!D:D,Sheet2!A:A,D5,Sheet2!B:B,D5)
The first formula can easily be modified to work with more than two criteria columns (e.g. if you wanted to match on serial number as well), but the second one can't.
To get the total quantity based on more than two columns, where a string can occur more than once in the same row, you would need an array formula like
=SUM(SIGN((Sheet2!A2:A10=D5)+(Sheet2!B2:B10=D5)+(Sheet2!C2:C10=D5))*Sheet2!D2:D10)
which must be entered with CtrlShiftEnter
I have some data.
I would like to find the "unique" values in the data. That is, not any data that was duplicated.
To be clear:
A
B
C
A
B
I want
C
I do not particularly care if this makes a new column of modifies the existing column. I do not, however, want to get C highlighted - my data sets are v. large and i really don't want to be scrolling along finding hyper-color yellow entries.
(I have a sneaking suspiscion this has been asked before, but given the dual connotations of "unique", it is kind of hard to search for it here)
Its a standard option of conditional formatting
Duplicate is the default, But the box allows unique too
That menu is accessed from home tab > conditional formatting > new rule
be sure to set a format for the cell then
Conditional Formatting and Filtering is much the simplest, but if you really want a formula to obtain the unique values in a different column:
=IF(COUNTIF($A$5:$A$15,A5)=1,A5,"")
This assumes the original data is in A5:A15, and this formula is entered into another column and copied down the same number of rows. You'll end up with a load of blank cells though. You'll need to copy/paste-special values, then sort in descending order (or filter) this list so that the blanks are at the bottom and can be deleted.
Actually, slightly better would be:
=IF(COUNTIF($A$5:$A$15,A5)=1,A5,"zzz")
because, after copy/paste-special values, you can sort in ascending order and you can see the values (at the bottom) that you need to delete.