Subsets, within Excel formula - excel

I would like to learn how to make Excel formulae understand my subsets. An Example:
Week Value Number Accept? First
1 a 11 TRUE a
1 b 12 TRUE FALSE
1 c 13 FALSE FALSE
2 d 13 FALSE f
2 e 12 FALSE FALSE
2 f 12 TRUE FALSE
3 g 12 FALSE #N/A
3 h 13 FALSE FALSE
3 i 13 FALSE FALSE
4 j 14 FALSE k
4 k 14 TRUE FALSE
4 l 12 TRUE FALSE
Column A (Week) defines subsets, separated for clarity.
"First" uses the formula
=IF(A1<>A2,INDEX($B$1:$B$100,MATCH(A2&TRUE,$A$1:$A$100&$C$1:$C$100,0))
Which allows me to select the first value which satisfies condition Accept?, within subsets (It seems rather inefficient, so if anyone has a better idea I'd gladly test it)
Now imagine the following data:
Value Time Price Trigger?
x 14 500
a 11 490
b 12 480
c 13 320
d 14 560
e 15 570 e
f 16 490
g 17 520 g
X is a comparison value. It has 2 parameters: Time & Price
"Trigger" searches for values in the list that have greater time and price than X (Row 2)
The formula for Trigger would be something like:
=IF(AND(B3>$B$2;C3>$C$2);B1;"")
But, how do I make this same thing work, within weeks ("subsets")?

=IF(IFERROR(INDEX(INDEX(A:A,MATCH(A2,A:A,0)):INDEX(D:D,COUNTIF(A:A,"<="&A2)+1),MATCH(TRUE,INDEX(D:D,MATCH(A2,A:A,0)):INDEX(D:D,COUNTIF(A:A,"<="&A2)+1),0),2)=B2,FALSE),B2,FALSE)
Here is the explanations:
INDEX(A:A,MATCH(A2,A:A,0)):INDEX(D:D,COUNTIF(A:A,"<="&A2)+1): This is to determine the range/subset that corresponds to the Week, so you will get $A$2:$D$4, $A$5:$D$7, $A$8:$D$10, $A$11:$D$13 as outcome.
MATCH(TRUE,INDEX(D:D,MATCH(A2,A:A,0)):INDEX(D:D,COUNTIF(A:A,"<="&A2)+1),0): You probably know this already. This is to satisfy the condition on Accept column. But I have to add another range by using INDEX again just for column Accept.
Then I used an IF function to determine if the result is equal to Value column, otherwise will output FALSE. You don't need this if you don't mind the same outcome for every cell on First column.
Lastly, I personally don't like those error code so used IFERROR to output the error message I prefer. You can remove that for your preference.
Hope this helps.

Related

What does this formula mean in excel? (A cell equals a range)

I see the following formula in a Excel spread sheet and can not understand... Can anyone explain what the test condition "N5=N4:N741" mean?
=MIN(IF(N5=N4:N741,K4:K741))
I made some experiments and still cannot get a clue...
I'm assuming this is an array formula.
What this does is takes the minimum of the range K4:K741 where the value in N4:N741 equals the value in N5.
Let's look at a smaller example. K4:N9 is shown below.
K L M N
----------
4 | 4 2
5 | 8 7
6 | 3 4
7 | 2 1
8 | 7 9
9 | 1 7
The expression N5=N4:N9 is true in row 5 and row 9 since both of those match N5 (value = 7), giving the array {False,True,False,False,False,True} Thus IF(N5=N4:N9,K4:K9) will return {False,8,False,False,False,1} since the True values are replaced by the corresponding row in column K. The MIN() function will then ignore the False parts and return the minimum of the corresponding values in column K (the value 1 since 1 < 8).
I believe it returns an array of true and false values. I also believe the true shows up for the 3 because it is the third item in the array. but that is a guess on my part.
{false, false, true, false,false}
If you change your 5 in E1 to a 1, it will return a true.
Research all of many things excel

Excel: Consider only cells with given value - Recursive formula

I'm trying to make a formula that lets me easily extrapolate a quality within a subser
Let's say I have the following set of data:
Week Name Accepted? Accept Week?
1 a TRUE
1 b TRUE
1 c TRUE
2 d FALSE
2 e TRUE
2 f TRUE
3 g FALSE
3 h FALSE
3 i FALSE
Three weeks, three entries each
I'm trying to make a formula that fills Column 4:
Week 1 would be TRUE because all three entries (B2:B4) are accepted week TRUE
Week 2 has a non accepted entry, therefore all three entries (B5:B7) are FALSE
Week 3 is false as well in Accept Week (B8:B10)
I would appreciate any tip you can give to me.
Use this formula:
=COUNTIFS(A:A,A2,C:C,TRUE) = COUNTIF(A:A,A2)

Concatenate values in columns/rows and getting the value of the result

I have an excel worksheet with something like below. The desired output are as shown in column G and the last row, which concatenates all the values in columns/rows and gives the value of the resultant expression.
It's actually some kind of a puzzle where the aim is to replace some numbers with operators such that the values in G matches with a specified value. I am replicating the same in excel from a paper version.
A B C D E F G
3 3 33
4 1 + 2 43
4 0 + 5 6 4 604
7 3 2 / 1 2 61
3 7 2 7 3727
3 0 30
47 4033 304 0.4 2617 42
I have tried the following formula:
="="&A2&B2&C2&D2&E2&F2
However it gives the result in text format instead of 43, which I expected:
=41+2
Is there any way to give the final output as 43.
I developed (recorded and modified) a macro which simply copies the above result, paste it as values in Column H and then run 'text to columns' on the column H which gives me the desired output exactly as expected. However, I still can't figure out how to do the same with the row.
Is there any way to achieve the above with a formula only?
I want to avoid using macros as the undo functionality is lost but suggestions are welcome.
You could create a UDF that uses Application.Evaluate to evaluate the text string into a value. Then your formula would just need =Eval(A2&B2&C2&D2&E2&F2)
Function Eval(txt As String)
Eval = Application.Evaluate(txt)
End Function

Excel array query

I'm struggling to understand the mechanics of a particular array formula. I have a row of data ranging from January 2015 to December 2016. Let's assume the data is populated up to October 2016 and the sum in October is £1,000. When data is entered into November 2016 say £1,250, the formula below automatically calculates the delta between the two months. How did the formula do that. Could someone help provide a simple explanation of the below, in particular how it knew to deduct the latest month from the prior month.
=(INDEX(60:60,MAX(IF(M60:AV60<>"",COLUMN(M60:AV60)))))-(INDEX(60:60,MAX(IF(M60:AV60<>"",COLUMN(M60:AV60)-1))))
Thanks for your help,
Miles
It's a little complex, but let's break it down a piece at a time.
This looks to be an array formula, which means that rather than dealing with a single cell, it can deal with a whole set of cells at once.
M60:AV60<>"" This segment produces an array (list) of TRUE and FALSE values, looking at each cell between M60 and AV60. Wherever the cell contains a value - ie is not blank - it returns TRUE. Wherever the cell does not contain a value, it returns FALSE. This list exists only in the program's working memory, and it isn't recorded anywhere in the sheet. So we have something like this:
TRUE
TRUE
TRUE
TRUE
TRUE
TRUE
FALSE
FALSE
FALSE
FALSE
FALSE
COLUMN(M60:AV60) This segment produces another array, the same size as the TRUE/FALSE array above, that simply contains the column numbers of every cell from M60 to AV60. We now have two lists - one containing TRUE/FALSE, and one containing numbers, both the same length.
TRUE | 1
TRUE | 2
TRUE | 3
TRUE | 4
TRUE | 5
TRUE | 6
FALSE | 7
FALSE | 8
FALSE | 9
FALSE | 10
FALSE | 11
IF(M60:AV60<>"",COLUMN(M60:AV60)) This IF statement combines the TRUE/FALSE array with the column numbers array to get something more useful. Wherever there is a TRUE in the first array, it is replaced with the corresponding number from the second array; wherever there is a FALSE in the first array, nothing is changed, and the value stays at FALSE. This way, we end up with a list of numbers, representing the columns of each non-blank cell. It's the equivalent of running the IF formula on all the members of the array.
IF | TRUE |THEN| 1 = 1
IF | TRUE |THEN| 2 = 2
IF | TRUE |THEN| 3 = 3
IF | TRUE |THEN| 4 = 4
IF | TRUE |THEN| 5 = 5
IF | TRUE |THEN| 6 = 6
IF | FALSE |THEN| 7 = 0
IF | FALSE |THEN| 8 = 0
IF | FALSE |THEN| 9 = 0
IF | FALSE |THEN| 10 = 0
IF | FALSE |THEN| 11 = 0
The last column, after the =, is what is passed to the MAX function.
MAX(IF(M60:AV60<>"",COLUMN(M60:AV60))) This segment cuts down the list of numbers to just one number, the Max or highest number in the list. Thus we end up with a single result, which represents the last column that contains a value.
INDEX(60:60,MAX(IF(M60:AV60<>"",COLUMN(M60:AV60))))) The INDEX function looks at all of row 60, and returns a value from a specified column in that row. That being the column returned by the previous segments - the last column that contains a value.
The second half of the formula with the second INDEX function does exactly the same thing, but it subtracts 1 from the column number returned - that is, it gets the second-to-last column that has a value.
The end result is subtracting the second-to-last value from the last value, to get the difference between them.

Identify Rows with Same Values in 2 Different Columns

I have a data set of roughly 405,000 rows and 23 columns. I need the records where the value in column "D" is the same as the value in column "H" for that row.
So for
A B C D E F G H
13 8 21 ok 3 S - of
51 7 22 no 3 A k no
24 3 23 by 3 S * we
24 4 24 we 3 S ! ok
24 9 25 by 3 S # we
75 2 26 ok 3 S 9 ok
etc...
I'd get back the 2nd row, the 6th row, etc...
A B C D E F G H
51 7 22 no 3 A k no
75 2 26 ok 3 S 9 ok
Based on other posts like: Formula to find matching row value based on cells in multiple columns I tried using a Pivot Table, but it complains I can't put either of my two columns in the "Columns" area because there is too much data. With both columns in the "Rows" area, I get a relationship of D to H, but I can't then find a way to filter on only those where D = H.
I've also looked into countifs(), vlookup, and index / match functions, but I can't figure this out. Help please.
I would do a simple "IF()" formula in a new column.
For your example add a new column I and use the following formula in the first data row (I2):
=IF(D2=H2,"Yes","No")
Fill down to the end of the data.
Then using Excel filters or countif you can check the number of "Yes" vs "No" in your data.

Resources