Excel part II: Take nth value within a sub set - excel-formula

Let me make a second part to another stupid question I can't sort. Imagine we have a list like
Week Value Accept? First
1 a TRUE a
1 b TRUE
1 c FALSE
2 d FALSE
2 e FALSE
2 f TRUE f
3 g FALSE
3 h FALSE
3 i FALSE
4 j FALSE
4 k TRUE k
4 l TRUE
How do I make a formula that outputs the first value within a subset with satisfies a condition.
In rows 2 to 4, it would be B2
In rows 5 to 7, it's B6
In rows 8 to 10 there is no answer: all false.
In rows 11 to 13, it will be B12, ignoring B13 which also is true.
I will appreciate any recommendation, thanks.

Assuming your titles starts in A1
Write in D2 :
{=IF(A1<>A2,INDEX($B$1:$B$100,MATCH(A2&TRUE,$A$1:$A$100&$C$1:$C$100,0))}
the {} shall be inserted by pressing ctrl+shift+enter (array formula)
then extend this formula all the way down. It should give you what you want.
What it does :
IF(A1<>A2,
will only display the result if the cell in the lefthand column is a new week number
INDEX($B$1:$B$100,
will return the n-th value of the column B, where n is :
MATCH(A2&TRUE,$A$1:$A$100&$C$1:$C$100,0)
will return the first line for which the columns A and C concatenated has for value A2&TRUE. It is the reason why you need to use array formula

Related

If cell is true take value from another column

Column A contains some numbers, while column B contains TRUE and FALSE values.
A B
- -
1 TRUE
2 FALSE
3 FALSE
4 TRUE
5 TRUE
In column C, for every TRUE value in column B, take the value in column A in order not the row the TRUE value in in.
For example:
C
-
1
FALSE
FALSE
2
3
When I try to do something like this, all the TRUE values take the number in column A in the row the TRUE value is in.
For example:
C
-
1
FALSE
FALSE
4
5
So, when the desired result is 2 and 3 in the last two TRUE values, the IF formula takes the value from column A in the row the TRUE value is in, which in this case is 4 and 5.
Is there any method to take the value in order if the value in column B is TRUE?
This formula seems to do the trick.
This is my testsheet:
In C2 I have this formula:
=IF(B2="True",1,"False")
In C3 (and drag down):
=IF(B3="True",1+MAX($C$2:C2),"False")
You need another assisting column, let's say D
D should work like this:
if B = true then take A value
if B = false then take previous D value (1 row up)
and then you'd be able to use D for your C - take D value instead of A.

Excel conditon if column a consist in column b

In excel, how can we return true or false in a column based on comparing 2 columns in each cell. for an example
we have a table looks like this in excel
ROW
Column : A | B | C |
1 apple motor
2 pineapple train
3 car plane
4 motor durian
in the given example of the table above.
in column C , first row should return true followed by false. i know we can compare directly using
=if(b1=a4,TRUE,FALSE)
in the first column , this will return true . but i want compare each cell in column b to column a. i have tried this in excel but its returning false instead of true
=if(b1=a1:a4,True,false)
What approach should i use ?
You can use array formula with OR:
=OR(B1=A:A)
Array formula after editing is confirmed by pressing ctrl + shift + enter
Or if you don't want to use an array formula, use COUNTIF:
=COUNTIF(A:A,B1)>0

Google Sheets - formula to return N first values from range A where MAX(range B)

F1:N1 with random numbers (can have duplicates).
F2:N2 with sorted numbers.
Need a formula to fill in A1:C1 with values from F2:N2 where F1:N1 has a maximum value.
In the example it should be 1,8,3 from F2:N2 - according to 9,9,8 from F1:N1.
_ A B C D E F G H I J K L M N
1 ? ? ? 9 3 8 1 5 5 3 9 8
2 1 2 3 4 5 6 7 8 9
You can do this with a "helper row" to create a list of unique ranks:
F3: =RANK(F1,$F$1:$N$1)+COUNTIF($F$1:F1,F1)-1
and fill right to N3
Since your values in F2:N2 are sequential {1...8}, you can use this formula:
A1: =MATCH(SMALL($F$3:$N$3,COLUMNS($A:A)),$F$3:$N$3,0)
and fill right to C1
If the values in F2:N2 are random, then you can use this:
A1: =INDEX($F$2:$N$2,1,MATCH(SMALL($F$3:$N$3,COLUMNS($A:A)),$F$3:$N$3,0))
and fill right to C1
Nobody has jumped in to offer a Google Sheets solution so here is one:
=query(transpose(sortn(transpose(F1:N2),3,,1,false,2,true)),"select Col1,Col2,Col3 limit 1 offset 1")
In A1. This is a self-expanding formula so does not need to be filled across and does not need helper rows.
EDIT
'Limit 1' may be omitted in the above formula as mentioned in the comment.
Also this is a little shorter:
=transpose(query(sortn(transpose(F1:N2),3,,1,false,2,true),"Select Col2"))
Formula in A1 = INDEX($F$2:$N$2,MATCH(COLUMN(A1),$F$3:$N$3,0)) and is dragged till C1
Formula in F3 = RANK(F1,$F$1:$N$1)+COUNTIF($F$1:F1,F1)-1 and is dragged till N3

Excel formula or VBA that

I have a worksheet with over 400,000 rows. A is the customer number, B customer name, There may be two or more variations of the Name with the same number. I want to make the names the same relative to the number so in a pivot table there is only one row per customer number. Example of data below.
Column: A,
Customer Number
DEEU9999684
DEEU9999684
DEEU9999684
Column B "Customer Name:"
ZWICKAU-XX
ZWICKAU
ZWICKAU
To make it easier I sorted by customer number, and can use the first instance of the "Customer Name" when then "Customer number" changes and where the number are equal. So the above example all the names can be "ZWICKAU-XX"
I was trying a combination of IF(AND but that obviously doesn't work, example ... =IF(AND(A1=A2, B1=B2, B1, B2)
Hope someone can save me form having to manually scrub 400,000 records.
Thanks, dkmanley
Enter the formula in cell C1: =FALSE (I mean enter text "FALSE" in C1)
and then copy this to column C: =IF(A2=A1;TRUE;FALSE) (Starting from C2)
Enter the formula in cell D1: =A1
Then copy this to column D: =IF(C2=FALSE;B2;D1) (Starting from D2)
Here is a sample:
1 a FALSE a
1 a TRUE a
1 a TRUE a
1 x TRUE a
1 x TRUE a
2 b FALSE b
2 b TRUE b
2 b TRUE b
2 bf TRUE b
2 c TRUE b
2 c TRUE b
3 d FALSE d
3 d TRUE d
3 d TRUE d
3 s TRUE d
3 c TRUE d
3 d TRUE d
3 s TRUE d
4 a FALSE a
4 d TRUE a
4 f TRUE a
4 g TRUE a
4 s TRUE a
4 a TRUE a
You could use something like
=INDEX(B:B,MATCH(A1,A:A,0))
and copy down. The data does not need to be sorted. The formula will return the name for the first occurrence of the number, starting from the top.

formula for finding the first non-empty cell

I have a spreadsheet with 2 columns of data, column A and B, and column C where I'm looking for the formula.
row A B C
1 50
2
3
4
5 56 6
6
7
8 46 10
9
10
11 64 18
As you can see, a row either contains a value or not. In column C, I'm looking to calculate the difference between
a) the value in column B and the value in column A's first non-empty cell directly above (so for example, at row 5, I calculate the difference between B5 and A1 56 - 50 = 6) if the value of B is a number and
b) the value in column A and the value in column B's first non-empty cell directly above (row 8, 56 - 46 = 10)
and put nothing if neither column A and B are empty.
I've been struggling with "first non-empty cell" to write an R1C1 formula. Note that I know I can do this in VBA but I'm looking for the R1C1 formula.
Thanks for your help.
Here is an array formula (that you need to validate with Ctrl + Shift + Enter) you can put in C1 and drag and drop till the end of your data:
=IF(OR(A1<>"",B1<>""),INDEX($B$1:B1,MAX(IF($B$1:B1="",0,ROW($B$1:B1))))-INDEX($A$1:A1,MAX(IF($A$1:A1="",0,ROW($A$1:A1)))),"")
Or, in a french version of Excel:
=SI(OU(A1<>"";B1<>"");INDEX($B$1:B1;MAX(SI($B$1:B1="";0;LIGNE($B$1:B1))))-INDEX($A$1:A1;MAX(SI($A$1:A1="";0;LIGNE($A$1:A1))));"")
Note that if you feel interested, you can commit into Stackoverflow in french
Perhaps try this formula in C2 copied down
=IF(B2="",IF(A2="","",LOOKUP(9.99E+307,B$1:B1)-A2),B2-LOOKUP(9.99E+307,A$1:A1))

Resources