Why doesn't this formula work? - excel

Consider the following (partial) Excel sheet:
| A | B C D
-+---+------------------
1|id | comp1 comp2 comp3
-+---+------------------
2| 1 | 1 0 0
3| 1 | 1 0 0
4| 2 | 0 1 0
5| 3 | 0 0 1
6| 1 | 1 0 0
7| 3 | 0 0 1
As an example, if filled in all zero's and one's in columns B, C and D by hand. I need to automate this because my dataset is to large to do it all manually. I need, for instance for cell B2, a formula which checks whether value of A2 is similar to company id in cell B1. If so, set a 1, else a 0. Another example: take row 4. It has company id 2 in cell A4 so B4 (comp1) should be 0, C4 1 and D4 0.
I have used the following formula in cell B2, ready to be dragged to all other cells:
=IF($A2=RIGHT(B$1;1);1;0)
However, it puts a 0 in B2. I don't understand, because A2 has value 1, and so does RIGHT(B1;1), so IF(1=1;1;0), so B2 should get value 1. But it doesn't where am I going wrong?

Because right() returns a string and you compare a string to a number. You need to transform that string to a number, e.g. with value(right(...)).

Related

Excel - Finding Cells with Top Values

| Company 1 | Company 2
Item 1 | 7 | 0
Item 2 | 1 | 0
Item 3 | 2 | 8
Item 4 | 0 | 3
Item 5 | 0 | 1
So I need to grab the cell/row number for the top 3 ordered values in a given column so for Company 1 you'd get B2, B4, B3 and for Company 2 you'd get C4, C5, C6.
To return the row number use this formula:
=MATCH(LARGE(B$2:B$6,ROW(1:1)),B:B,0)

Excel macro to find a date in a range and then count for next value change in an adjacent column

I am attempting to write a macro to find February 2nd of each year in column A and then count the number of rows (days) until the value in column B changes. This count could be put in a new column, column C, but on the same row as the February 2nd that it correlates to, in this case row 3.
Using the table below the output to C3 would be 5. I am not counting the day of February 2nd but I am counting the day the change occurs. This is for 100+ years that I will need to loop through.
id | A | B | C
----------------------------
1 | 1946/01/31 | 0 |
2 | 1946/02/01 | 0 |
3 | 1946/02/02 | 0 |
4 | 1946/02/03 | 0 |
5 | 1946/02/04 | 0 |
6 | 1946/02/05 | 0 |
7 | 1946/02/06 | 0 |
8 | 1946/02/07 | 2 |
9 | 1946/02/08 | 0 |
The real challenge is to do it with a formula. Well, 2 formulas.
The first formula in cell E2 finds the date 2nd Feb by looking for "02/02" at the end of the text in column B and if it is found it places the contents of C2 in that cell. if it's not found it compares C1 with D1, the 2 cells above to see if they are the same because a match was previously found and if so it takes the contents of the cell above. This results in the zeros you can see in column E between 2nd Feb and the point where column C changes.
Formula for E2 and then autofill down to the end of your data
=IF(AND(MONTH(B2)=2,DAY(B2)=2),C1,IF(AND(E1<>"",E1=C1),E1,""))
Now all we need to do is count the cells in column D by looking for the first non blank cell in column D AND(E1="",E2<>"") and then count all the cells that match that cell. I'm not sure what gap you're expecting to find but you can change the 200 to ensure that you count everything. The last part is to take away 1 so that the 2nd feb row is not being counted.
Formula for D2 and then autofill down to the end of your data
=if(AND(E1="",E2<>""),countif(E2:E200,E2)-1,"")

duplicate for every block

I have this Excel table example:
A B C D
--------------
1 | 1 a 1 x
2 | b 1
3 | c 2
4 | a 3 x
5 | 2 r 4 x
6 | r 4 x
7 | t 1
8 | 4
9 | 3 a 1
10| b 3 x
11| c 3
12| b 6 x
I need to find duplicates (marked with x in column D) for every each block, but only in the context of it's own block (a block is what is found between A1 and A4 - for 1, another block is from A5 to A8 - for 2, and so on). B1=a it's not a duplicate for B9=a, because B9 belongs to block 3 and B1 belongs to block 1. But B1 is a duplicate for B4, they are on the same block, therefore both B1 and B4 should be marked with x.
I'm struggle with dynamic range finding/composition:
Basically I need in column D to find the range (starting with position in D first not empty field in A up, and first not empty field in A down). Eg: in D4 I need to get first non empty in A is A1, and first non empty in A is A5, and construct the range as A1:A5-1.
Use a helper column to avoid the need of an array formula:
In d2 put:
=IF(A2="",D1,A2)
Which will fill in the missing column A values:
Then in E2:
=IF(COUNTIFS(D:D,D2,B:B,B2)>1,"x","")
If you want the array formula:
=IF(COUNTIF(INDEX(B:B,AGGREGATE(14,6,ROW($A$1:INDEX(A:A,ROW()))/($A$1:INDEX(A:A,ROW())<>""),1)):INDEX(B:B,IFERROR(AGGREGATE(15,6,ROW(INDEX(A:A,ROW()+1):INDEX(A:A,MATCH("zzz",B:B)))/(INDEX(A:A,ROW()+1):INDEX(A:A,MATCH("zzz",B:B))<>""),1)-1,MATCH("zzz",B:B))),B2)>1,"x","")

Identify first occurrence of an entry in a list, if certain criteria is met (EXCEL)

I have spent too much time trying to figure our the question imposed, in the title of this question, and am reaching out for some help.
I would like to output an entry of 1 for the first occurrence when criteria is equal to AR and output an entry of 1 for the first occurrence on a column when criteria is equal to SFR on a seperate column.
For example the columns I'd want in the following table are the columns titled AR and SFR
|Property Name | product | company | AR | SFR |
|---------------|---------|---------|----|-----|
|orange grove | 2 | SFR | 0 | 1 |
|orange grove | 1 | AR | 1 | 0 |
|orange grove | 6 | AR | 0 | 0 |
|garden court | 2 | SFR | 0 | 1 |
|garden court | 1 | AR | 1 | 0 |
|chimney sweeps | 6 | AR | 1 | 0 |
|chimney sweeps | 2 | SFR | 0 | 1 |
|chimney sweeps | 1 | AR | 0 | 0 |
|chimney sweeps | 4 | SFR | 0 | 0 |
|downing apts | 2 | SFR | 0 | 1 |
|downing apts | 1 | SFR | 0 | 0 |
|downing apts | 6 | AR | 1 | 0 |
I tried implementing countif within my formula and only taking into consideration when my output is a result of 1, then nesting the formula for criteria "AR" or "SFR" with the result of my countif, if the criteria is satisfied, but the table isn't organized so that AR comes first in the table row and vice versa. Here is an example of my formula:
=IF(E2="AR", IF(COUNTIF($C$2:C2,C2)=1,1,""), "")
Sometimes I'll have instances where the company name occurs but the count isn't 1. Take for example orange grove. Orange grove's count would be 1, 2, 3 consecutively, for each +1 instance. If my count is 1 and SFR, my formula would output a 1 but if my criteria is AR and the count is not 1 (it's actually 2 or 3), I don't get a first occurrence output per my criteria of AR.
I saw there may be a way to utilize sumproduct but I am not familiar with it.
Could anyone please help. Anything would be appreciated!
It would guanrantee you a result if you could CONCATENATE the Property Name and Company and then input the below mentioned formula into AR and SFR cells.
Insert a column and use =CONCATENATE(A2," ",C2) to merge Product
Name and Company. It should give you result in space delimited
format. For eg. orange grove SFR, chimney sweeps AR, etc.
Enter this formula in Cell E2 which belongs under AR column: =IF(TRIM(RIGHT($D2,3))=E$1,IF(OR(COUNTIF($D:$D,$D2)=1,MATCH($D2,$D:$D,0)>=ROW($D2)),1,0),0)
Drag the formula left onto Cell F2 to apply to SFR column and then to the bottom of each columns to apply for all records/rows.
In the end you will have the following result as expected:
Table:
R/C A B C D E F
01 Property Name product company Merged PN + C AR SFR
-------------------------------------------------------------------------
02 orange grove 2 SFR orange grove SFR 0 1
03 orange grove 1 AR orange grove AR 1 0
04 orange grove 6 AR orange grove AR 0 0
05 garden court 2 SFR garden court SFR 0 1
06 garden court 1 AR garden court AR 1 0
07 chimney sweeps 6 AR chimney sweeps AR 1 0
08 chimney sweeps 2 SFR chimney sweeps SFR 0 1
09 chimney sweeps 1 AR chimney sweeps AR 0 0
10 chimney sweeps 4 SFR chimney sweeps SFR 0 0
11 downing apts 2 SFR downing apts SFR 0 1
12 downing apts 1 SFR downing apts SFR 0 0
13 downing apts 6 AR downing apts AR 1 0
Explanation:
We merged Product Name & Company to identify unique records.
Then we created a condition to check for last 3 characters to match our column name: =IF(TRIM(RIGHT($D2,3))=E$1
If the above condition is true which means that we are in the correct Company column, we can now proceed to check if the Product Name instance is first or not. If not, then we are in the wrong column so just print 0.
As you mentioned there can be either a unique combination or multiple combinations of Product Name & Company. Therefore there are 2 conditions:
a. When combination is unique i.e. count is equal to 1: COUNTIF($D:$D,$D2)=1
b. When combination is duplicate but row number of first instance is less than equal to current row number: MATCH($D4,$D:$D,0)>=ROW($D4)
If either of the above 2 conditions are TRUE then the record is first instance and hence print 1, else it is not and hence print 0.
Hope it helped.
Assuming Column D and E are where your AR and SFR columns are respectively, try:
Table Structure:
AR SFR
AR 1 0
AR 0 0
AR 0 0
AR 0 0
AR 0 0
SFR 0 1
Cell D2 Would be (assuming AR is your column Header for column D)
=IF(C2=D1,1,0)
E2 Would be:
=IF(C2=E1,1,0)
For D3, then drag down for each cell in column D
=IF(SUM(D$2:D2)=0,IF($C3=D$1,1,0),0)
For E3, then drag down for each cell in column E
IF(SUM(E$2:E2)=0,IF($C3=E$1,1,0),0)
Thanks!
Ryan

Excel Table lookup

A B C D E F G H I J K L M N O P
1 In Use |1 0 0 0 0 0 0 0 0 0 0 0 0 0 0|
2 Item Value |1 0 0 0 0 0 1 1 0 1 1 1 0 0 0|
3 Data |3 4 5 6 7 8 9 1 2 3 4 5 6 7 8|
I'm looking for an excel function that will compare the values of Rows 1 and 2 to see if they both equal 1. If they are both 1, I would like for it to return the value of the third row (of the corresponding column who has both values equal to 1) to the cell. So in this example, I am looking for the function to return the value 3.
What is the best function to achieve the desired result? I have tried the AND() function like so:
=and(B1:P1=1,B2:P2=1,B3:P3,0)
Will this go in each column? Or are you looking for a single cell that sums them all? If you are looking for one formula to check everything, would this work?
=SUMPRODUCT(B1:P1,B2:P2,B3:P3)
Note that this depends on the values being 1 or 0, and that only one pair of (1,1) exists.

Resources