Is there an Excel formula that can provide cell position based on change from TRUE to FALSE? - excel

all:
I am trying to create an excel formula that find the titration point of a string of true and false statements (shown as 1s and 0s). I cant figure out how to use INDEX MATCH to find the column where the cell values change.
Here is a visual example:
Column 1 2 3 4 5 6
Answers 0 0 0 1 1 1 ----> I want the formula to show the average of "3" and "4" (=3.5)
0 0 0 0 1 1 ----> I want the formula to show the average of "4" and "5" (=4.5)
Some notes: all column headers are numbers, so finding the average should be possible. Also, some rows may start with "1" and then transition to "0".
Any advice or help will be greatly appreciated! Thank you!

If the numbers are sequential and match the column number then:
=MATCH(1,A2:F2,0)-0.5
If they they don't:
=AVERAGE(INDEX(A$1:F$1,MATCH(1,A2:F2,0)-1),INDEX(A$1:F$1,MATCH(1,A2:F2,0)))

Related

Excel counting cells based on complex criteria

Hate asking question about something as simple as an Excel formula, but seem to really need and would appreciate the help.
I have a table where the rows headings contains names and the column headings contains week numbers. Within this table I have differents numbers. Both numbers that are plus and negatives.
I want to count each cell where the row heading matches a specific name and then each cell that has a plus value with a week number less than or equal to a certain week.
I have tried to got it to work with at least some function (without it caring about plus and negative values) but haven't even gotten that to work.
I've tried with:
=SUMPRODUCT((Data!F3:F28=I1)*(Data!I2:BI2="<="&A1)*(Data!I3:BI28))
=SUMIFS(Data!I3:BI28;Data!F3:F28;I1;Data!I2:BI2;"<="&A1)
.............1 2 3 4 5
name1 -1 4 3 1 1
name2 0 0 0 0 0
I want a formula that counts for example every column header with a value less than or equal to (for example) 4, but excludes negatives and vice versa. So for the example above, the result of name1 should be 8; counts week 2, 3 and 4.
For your current example:
Formula in H3:
=SUMPRODUCT((B2:F3>=0)*(B1:F1<=4)*(A2:A3="name1"),B2:F3)

Excel formula that returns specific lists of values?

Help is appreciated!
I have two columns of data. The first is a participant ID column. The second adjacent column are the binary coded respective responses (example below). I am interested in all of the 1's.
Does anyone know a formula which can extract a list of all of the participants who have scored a 1?
E.g., (Particpant ID is value on the left, and the participants' score is to the right).
1 0
2 1
3 1
4 0
5 0
6 1
FILTER() formula will do that. Try-
=FILTER(A2:A7,B2:B7=1)

Excel sum one column based on another

I have data that is divided into columns as follows:
Runs RunsAfter Switch New
0 2 1
0 2 0
1 2 0
0 1 0
1 1 0
0 0 0
0 0 0
0 0 1
0 1 0
1 1 0
0 0 0
I want excel to sum the Runs column by taking each cell and summing down the remainder of the column until there is a 1 in the Switch column. It should then start calculating again until another Switch. All of this output should be put in the New column. The result should look like the RunsAfter column, which I am currently calculating by hand. I would keep doing this, but the dataset is going to get too big to continue doing this by hand.
I've checked for questions similar to this, but haven't been able to find quite what I'm looking for. If I've missed an answer elsewhere, please let me know.
If I am understanding correctly, I think you want to use a combination of the match formula to find the next "switch" and the indirect formula to define the range to sum. I can't think of a simple way to do this.
This is assuming that your headers are in row 1 and your columns are Runs (A), RunsAfter (B), Switch (C), and results in D. I've used 100 for your last row, but you will need to change that if you have more rows. This is what I did in D2:
To find the next row for which Switch is 1:
MATCH(1,C3:$C$100,0)+ROW()
I also included iferror to make it not break for rows after the last switch:
IFERROR(MATCH(1,C3:$C$100,0)+ROW()-1,100)
I included this as part of the indirect formula to tell it what range to sum up:
D2=SUM( INDIRECT("A"&ROW()&":A$"&IFERROR(MATCH(1,C3:$C$100,0)+ROW()-1,100)))
So for D2, it's summing from A2 to the row before the next switch, in this case row 8. You should be able to drag it down from D2 with those anchors.

How to count number of matches between two columns in Excel?

How to count number of matches between two columns in Excel?
For example if we have:
1 1
2 1
3 2
4 4
5 3
I need to get either a column like this:
1
0
0
1
0
and then I can sum the ones in there to get the count of matches.
Option 1: IF
=IF(A1=B1;1;0)
This formula will put 1 in the cell if A1 = B1, and 0 otherwise.
Option 2: COUNTIF
Write =A1=B1 in C1, etc., in the column cells. This will fill the C column with TRUE and FALSE values.
At the bottom of that column, add a cell =COUNTIF(C1:C100;TRUE) so that you count the cells between C1 and C100 which have value TRUE.
You may find the TechRepublic article Use COUNTIFS() to compare two data sets in Excel of use. See also Microsoft's documentation on countifs().

excel formula how to build similarity matrix

I would like to create a formula that will create a similarity matrix from a table of data. Here is an example of the data followed by the desired output. The rows of data represent the result of a modularity class algorithm. I need my output to calculate the number of months two countries share the same class value (It can be any value as long as they are equal) divided by the number of total months.
Input modularity class
jan feb mar apr may
USA 0 1 2 4 3
UK 0 3 2 3 3
AU 0 2 2 2 3
CH 1 0 1 1 2
EG 2 3 0 0 1
Output similarity matrix
USA UK AU CH EG
USA 1
UK 0.6 1
AU 0.6 0.6 1
CH 0 0 0 1
EG 0 0.2 0 0 1
I have not tried any formula because I dont understand where to begin. I have read about countifs and mmult, but I dont know what is most appropriate.
Right, there is a way using SUM(), IF(), COUNT() and using array formulas.
The basic formula that you could use is (assuming your top array is A1:F6, including the headers, so the data is in A2:F6):
{=SUM(IF($B$2:$F$2=$B2:$F2,1,0))/COUNT($B$2:$F$2)}
Using array formulas, you can make the IF() function return 1 for a match, and 0 for a mismatch, iterating through each element in a row. SUM() adds the matches up, and then dividing by the COUNT() of the number of cells processed gives you your similarity index.
The example above is for the top USA/USA cell in your example, you can fill down with that, but each new diagonal needs adjusting to change the fixed row number to the new row. So the top of the UK column would be:
{=SUM(IF($B$3:$F$3=$B3:$F3,1,0))/COUNT($B$3:$F$3)}
The COUNT() could be removed if you know how many columns/countries there are in advance.
Note: You do not type the curly braces. When you have finished entering the formula you have to press Ctrl-Shift-Enter whilst editing, to get those to appear and for the formula to be treated as an array formula. These formulas are often called CSE formulas for this reason (Ctrl-Shift-Enter).
Update:
You can do it with a single formula, filled over the cells, using INDIRECT() and COLUMN() as well.
{=SUM(IF(INDIRECT("$B$"&COLUMN(B2)):INDIRECT("$F$"&COLUMN(B2))=$B2:$F2,1,0))/COUNT(INDIRECT("$B$"&COLUMN(B2)):INDIRECT("$F$"&COLUMN(B2)))}
This uses the fact that the column number is the same as the row number, providing the transposition.
Update 2:
Actually, the COUNT() can be eliminated and SUM() replaced with AVERAGE() as all matches are 1, the mean is the correct value.
So this works for all cells:
{=AVERAGE(IF(INDIRECT("$B$"&COLUMN(B2)):INDIRECT("$F$"&COLUMN(B2))=$B2:$F2,1,0))}
Update 3:
If you desparately need nothing to appear on the upper diagonal side, making a lower triangular block, then you can use an IF() wrapping the above formula, checking to see if the column is greater than the row and making the cell blank in that case. You can then fill the entire block with the formula and it will look right, with no need for deleting.
{=IF(COLUMN(B2)>ROW(B2),"",AVERAGE(IF(INDIRECT("$B$"&COLUMN(B2)):INDIRECT("$F$"&COLUMN(B2))=$B2:$F2,1,0)))}
I'm going to provide a nudge in the right direction, rather than the whole solution. I think you'll be able to generalize the solution from the formulas given.
I placed your input matrix in A1:F6. Then I set up an intermediate matrix. A9 is simply "Matches in column 1."
===edit: Using month names in columns ===
Then I copied the month names jan .. may in B10:F10. Also USA .. EG in A11 .. A15.
Then in B12, the fun starts. I put a formula, =IF(B3=B2,1,0). What this does is it places a 1 in the cell if B3=B2, or a 0 otherwise. Then I fill right from B12 to F12 and I get the following row calculated:
1 0 1 0 1
You will note that these are the months when UK = USA.
If you take B12 and fill down to B15 and then fill B12 .. B15 right to F15, you will get the difference between each country and its adjacent neighbor. My matrix turned out to be:
jan feb mar apr may
USA
UK 1 0 1 0 1
AU 1 0 1 0 1
CH 0 0 0 0 0
EG 0 0 0 0 0
If you divide the sum of the rows by the number of countries, you will get 3/5, 3/5, 0/5, 0/5. These correspond to the output matrix of your first column, 0.6, 0.6, 0, 0.

Resources