Excel - Replace blank if only 1 contiguous value - excel

Okay this one is a bit strange to explain, but I have a file like this:
A B
1 | Person
2 | Person test
3 | Record
4 | Record test
5 | Tiger
6 | Scott
7 | Scott test
8 | Scott test
9 | Scott test
As you can see, in column A the first row where a new value starts, column B is blank. What I need is to fill in a placeholder (NULL) value into column B if there is only one contiguous value in column A. So for the above example row 5 only has 1 contiguous value so the result should look like this:
A B
1 | Person
2 | Person test
3 | Record
4 | Record test
5 | Tiger (NULL)
6 | Scott
7 | Scott test
8 | Scott test
9 | Scott test
I tried something like this but doesn't work:
IF(EXACT($A5,$A4)=FALSE AND EXACT($A5,$A6)=FALSE, "(NULL)", $B5)
I just want a formula I can paste all the way down column B. Any suggestions?

=IF(OR(A2=A1,A2=A3),"Test","(NULL)")
Replace Test and (NULL) with the values you want to display.
This checks to see if the AX = A(X-1) or A(X+1). If either of those is true, then it means that AX is contiguous with another row.
I should note that I tested this with Excel 2013.
Also, if you want the formula to use the value already in BX when the rows are contiguous, then you can't do that in the same column.
I'm not sure if that's what you're asking to do, but the formula you tried would have been attempting to do that, creating a circular reference.
You can easily do this in column C. Replace "Test" with BX. Then, if you only want 2 rows in the end, you can copy and paste the values of column C into column B, then delete column C. But, this way you'll lose your formula.

Suppose you have your data like this:
This formula seem to work:
=IF(OR(A2=A1,A2=A3),IF(B2="","",B2),"(NULL)")

Related

Generate new table from a current table in excel

I have sample table like this:
ID | 1 | 2 | 3
-------------
1 | 0 | 1 | 0
--------------
2 | 1 | 1 | 1
Then I want to generate a new table from that table. It will take the second row (1) then compare with each column (1, 2, 3) then print value of the matrix ( 0 - 1 - 0 ). For example:
Row_ID | Column_ID | Value
--------------------------
1 | 1 | 0
--------------------------
1 | 2 | 1
--------------------------
1 | 3 | 0
--------------------------
2 | 1 | 1
--------------------------
2 | 2 | 1
--------------------------
2 | 3 | 1
I'm not sure how or where to start by using formula. Please help. Thanks,
Well. There's no single formula that's going to do the job, obviously, but we have a few options we can use. I'll assume that the new table is going to start in cell A1 of Sheet2. Adjust accordingly.
Start with manually entered headers
Row_ID | Column_ID | Value
In the first column, first row, enter a 1. In rows below, use this formula: =IF(B3<B2,A2+1,A2) This will increment the value in the first column by 1 each time the second column resets its numbering.
In the second column, first row, enter a 1. The formula we'll use for this one will need some tweaking, but the basic version is: =IF(MOD(ROW()**+1**,**3**)=0,1,B2+1)
This formula is going to essentially count up to a certain point, then reset its numbering. The point it will count to, and where it will reset, will vary depending on the amount of data you have and which row you're starting from. Replace the 3 with the number of data columns you have, and remove the **s. The +1 is needed to increase the Row() counter to the SAME NUMBER as your number of data columns. So in my example, with 3 data columns and starting on row 2, the ROW() function gives us 2, so we need to add 1 to that to get up to a total of 3. If I had 5 data columns, I would add 3 to the total. Hope that makes sense.
These two formulae should give you a set of row and column numbers. Copying the formula down will force the values to increase as needed, thus:
Row_ID | Column_ID | Value
1 | 1 |
1 | 2 |
1 | 3 |
2 | 1 |
...etc.
Finally, to bring in the values, we'll use an OFFSET formula in the Value column: =OFFSET(Sheet1!$A$1,A2,B2) That formula starts from a reference cell - A1, in this case - then moves down x number of rows and across y number of columns to return a value. X and Y are provided by the formulas we already have. Your final structure will be something like this:
Row_ID | Column_ID | Value
1 | 1 |=OFFSET(...
=IF(...|=IF(MOD(...|=OFFSET(...
I hope all that made sense. Please let me know if there's anything that doesn't, and I'll try to troubleshoot.
EDITED TO ADD:
If the Row ID is something like a key that needs to be included with each value, we can get that fairly easily. We'll include another column with a slightly modified OFFSET formula: =OFFSET(Sheet1!$A$1,A2,0)
With this version of the formula we're not changing the column as we go down, just the row when it changes. It allows the values in the first row to be repeated in every row of the table. So this is my input:
And this is my output:
Notice that the ID repeats on each line of the output for the same item.

Microsoft Excel Multiple Worksheets and Data

I have two spreadsheets built. I want to be able to put what step a teacher is in which looks like this; BS, 1 or BS, 2 etc. (My second worksheet has each step and salary on it) I then would like the cell directly next to it to pull the correct salary amount from my other Worksheet.
I would add a picture, however it won't let me. Thank you for any help you can offer me.
Assuming the name of the teacher and category of the teacher is in Sheet1 columns A and B
(A) | (B)
|
Max | 1
Tammy | 4
Alex | 2
and on Sheet 2 you have category and salary
(A) | (B)
|
1 | 30000
2 | 45000
3 | 75000
4 | 120000
Then in cell C1 on sheet 1 you would use the formula:
=VLOOKUP($B1,'Sheet2!$A$1:$B$4,2,0)
You would then copy this formula down as required.
Alternatively you could achieve the same results with an INDEX/MATCH combination
=INDEX('Sheet2'!$B$1:$B$4,MATCH(B1,'Sheet2'!$A1:$A$2),0)

Find cell name with cell contents in Excel

Say I have a table like this (the letters at the top and numbers down the side represent row/columns):
| A | B | C | D
------+----+----+----
1 | 1 | 2 | 3 | 4
2 | 5 | 6 | 7 | 8
and I want to find the cell name using the cell contents, so if the input into my function was 5, the function would return A2, as that is the position at which 5 is located.
If your data is within columns A to Z and there is only one occurrence of the particular value you are looking for, you can use the following formula:
=CHAR(SUMPRODUCT((A1:D2=5)*COLUMN(A1:D2))+64)&SUMPRODUCT((A1:D2=5)*ROW(A1:D2))
SUMPRODUCT((A1:D2=5)*COLUMN(A1:D2)) returns the column number where 5 is located.
SUMPRODUCT((A1:D2=5)*ROW(A1:D2)) returns the row number where 5 is located.
CHAR(65) gives A, so you add the column number to 64 to get the column letter.
E.g. if it is the first column, you get CHAR(1+64) which is CHAR(65) which is A.

Counting the number of older siblings in an Excel spreadsheet

I have a longitudinal spreadsheet of adolescent growth.
ID | CollectionDate | DOB | MOTHER ID | Sex
1 | 1Aug03 | 3Apr90 | 12 | 1
1 | 4Sept04 | 3Apr90 | 12 | 1
1 | 1Sept05 | 3Apr90 | 12 | 1
2 | 1Aug03 | 21Dec91 | 12 | 0
2 | 4Sept04 | 21Dec91 | 12 | 0
2 | 1Sept05 | 21Dec91 | 12 | 0
3 | 1Aug03 | 30Jan89 | 23 | 0
3 | 4Sept04 | 30Jan89 | 23 | 0
This is a sample of how my data is formatted and some of the variables that I have. As you can see, since it is longitudinal, each individual has multiple measurements. In the actual database there are over 10 measurements per individual and over 250 individuals.
What I am wanting to do is input a value signifying the number of older brothers and older sisters each individual has. That is why I have included the Mother ID (because it represents genetic relatedness) and sex. These new variable columns would just say how many older siblings of each sex each individual has. Is there a formula that I could use to do this quickly?
=COUNTIFS($B:$B,"<>"&$B2,$H:$H,$H2,$AI:$AI,$AI2,$J:$J,"<"&$J2)
Create a column named Distinct with this formula
=1/COUNTIF([ID],[#ID])
Then you can find all the older 0-sexed siblings like this
=SUMPRODUCT(([DOB]>[#DOB])*([MOTHERID]=[#MOTHERID])*([Sex]=0)*([Distinct]))
Note that I made the data a Table and used table notation. If you're not familiar [COLUMNNAME] refers to the whole column and [#COLUMNNAME] refers to the value in that column on the current row. It's similar to saying $A:$A and A2 if you're dealing with column A.
The first formula gives you a value to count that will always result in 1 for a particular ID. So ID=1 has three lines and Distinct will result in .33333 for each line. When you add up the three lines you get 1. This is similar to a SELECT DISTINCT in Sql parlance.
The SUMPRODUCT formula sums [Distinct] for every row where the DOB is greater than the current DOB, the Mother is the same as the current Mother, and the Sex is zero.
I have a possible solution. It involves adding two columns -- One for "# older siblings" and one for "unique?". So here are all the headings I have currently:
A -- ID
B -- CollectionDate
C -- DOB
D -- MOTHER ID
E -- Sex
F -- # older siblings
G -- unique?
In G2, I added the following formula:
=IF(A2=A1,0,1)
And dragged down. As long as the data is sorted by ID, this will only display "1" once for each unique person.
In F2, I added the following formula:
=COUNTIFS(G:G,"=1",D:D,"="&D2,C:C,"<"&C2)
And dragged down. It seemed to work correctly for the sample data you provided.
The stipulations are:
You would need the two columns.
The data would need to be sorted by ID
I hope this helps.
You need a formula like this (for example, for row 2):
=COUNTIFS($A:$A,"<>"&$A2,$E:$E,$E2,$D:$D,$D2,$C:$C,"<"&$C2)
Assuming E:E is column for sex, D:D is column for mother ID and C:C is column for DOB.
Write this formula in H2 cell for example and drag it down.

How to compare two columns value in excel?

I have over 100k rows of data like below:
ALLA,ALLA,"Company1, Inc.","Company1, Inc.",PSA,PSA,1,1,FALSE,FALSE
BCCO,BCCO,"Company2, Inc.","Company2, Inc.",PSB,PSB,1,1,FALSE,FALSE
CTTP,CTTP,"Company3, Inc.","Company3, Inc.",PSC,PSC,1,1,FALSE,FALSE
CMMZ,CMMZ,"Company4, Inc.","Company4, Inc.",PSD,PSD,1,1,FALSE,FALSE
I want to know how to figure if data in column 1 is the same as column 2, column 3 as column 4 and so on. How could I do that in excel?
Following Cory's formula, I found that I can compare whole columns using:
=if(A:A=B:B, "yay", "aww")
Problem is I have a header in the file:
c - symbol, symbol, c - companyname, companyname, c - tradingvenue, tradingvenue, c - tierrank, tierrank, c - iscaveatemptor, iscaveatemptor
Shouldn't this cause A:A=B:B to be false?
Given this:
| A | B |
---+-----+-----+
1 | X | X |
---+-----+-----+
2 | Y | Y |
---+-----+-----+
3 | Z | Z |
The formula =SUMPRODUCT(--(A1:A3=B1:B3)) will tell you how many times the A value matches the B value.
You should get 3 as a result here. If, for example, you change B3 to Q then it will give you 2.
To do this on two columns without specifying the end of the range, try:
=SUMPRODUCT(--(A:A=B:B),--(LEN(A:A)>0))
I've been using Excel since 1991, and unless you want to write a VB macro, I think the best way is to do the simple IF statement suggested in the comments. If you need to test several columns at once, which is what your question suggests, then I'd do
=IF(AND(A1=B1,C1=D1,E1=F1,G1=H1),0,1)
Fill that formula down the column and then you'll be able toinstantly count the number of rows that don't matchwith a data-filter, select all the rows which have a '1', so you'll be able to examine the rows that don't match

Resources