How to test element in one Excel array is present in another - excel

I've got a spreadsheet of time series data with a series of columns that mark the presence of certain events that took place.
Like so:
A B C D
1 Date Event1 Event2 Event3
2 24/10/2016 T NULL NULL
3 31/10/2016 S NULL NULL
4 06/10/2016 NULL NULL NULL
5 20/10/2016 V NULL NULL
6 20/10/2016 T S V
7 01/12/2016 T NULL NULL
8 01/12/2016 S T NULL
9 29/11/2016 NULL NULL NULL
10 10/10/2016 T NULL NULL
I've then got a lookup table with a column of the events:
A
1 T
2 S
3 V
What I'd like to do is create a new column in the time series to flag a single value, say 1, if at least one, but possibly more, of the events in the lookup has taken place.
What's an effective way of doing that?
UPDATE:
The problem is more complicated that there may be non-NULL event types that don't appear in my look up list and for which I wouldn't want to trigger the flag.
For instance if I had:
9 29/11/2016 G NULL NULL
I would want to flag 0, but
10 10/10/2016 G T NULL
I would want to flag 1.

My understanding is that it is sufficient to check if the Event1 column has one of the values in your lookup table.
For simplicity I will imply that both tables are in distinct sheets.
Hence, all you need to do is apply the VLOOKUP formula on the newly created column in the first sheet (let's simply call it "Flag").
The formula for the first cell (E2) should be:
=VLOOKUP(B2, Sheet2!A:A, 1, false)
Just drag the same formula to the rest of the rows or double-click the bottom-right corner of this cell and you should be good to go.
This will also show you what the first event for that date is. If you only want a bit value (1/0), you can encase the formula in a simple IF.
Hope this helps!
EDIT:
After the new info, the solution doesn't change much:
=IF(IsNA(VLOOKUP(B2, Sheet2!A:A, 1, false)), 0, 1) + IF(IsNA(VLOOKUP(C2, Sheet2!A:A, 1, false)), 0, 1) + IF(IsNA(VLOOKUP(D2, Sheet2!A:A, 1, false)), 0, 1)
This will even tell you how many of those values each row has.

Related

Presenting a value based on number or text in cell

I have a list of 4 values in Sheet1 and 4 values in Sheet2.
In Sheet3 I will combine a random selection of these numbers and return the value in a column. (edit: no random selection from Excel, its a part picked from a bucket)
(A fifth column in Sheet3 will be used to do calculations with ValueS1 and ValueS2)
Sheet1
NumberS1
ValueS1
1
17.10
2
17.20
3
17.12
4
17.15
Sheet2
NumberS2
ValueS2
1
16.10
2
16.20
3
16.12
4
16.15
Sheet3
NumberS1
NumberS2
ValueS1
ValueS2
1
3
17.10
16.12
2
2
17.20
16.20
4
1
17.15
16.10
3
4
17.12
16.15
What kind of function can give the desired return?
I have looked into examples using "Indirect" but cannot see how they will solve my problem.
for the randomization: =ROUNDUP(RAND()*4,0)
rand() gives you a number between 0 and 1, so rand()*4 gives you a number between 0 and 4.
roundup(x,y) round up the number x with y digits you want to round the number up to (in our case 0).
for import the right number from sheet 1 or 2: =VLOOKUP(A1,Sheet1!A1:B2,2,0)
A1 - The value you look for in sheet 1 or 2.
Sheet1!A1:B4 - The array he look for your value on the firs column, always on the first column.
2 - The column you want to import the value from. (because we write an array of tow columns. we can write here only 1 or 2)
0 - it's an Optionally index (0 or 1). o is if you want an exact match of the return value.
Regular Lookup could do:
=LOOKUP(A2:A5,Sheet1!A2:A5,Sheet1!B2:B5) in Sheet3!C2
And
=LOOKUP(B2:B5,Sheet2!A2:A5,Sheet2!B2:B5) in Sheet3!D2
Note that LOOKUP will give the result to the closest match smaller than the search value.
Or VLOOKUP:
=VLOOKUP(A2:A5,Sheet1!A2:B5,2,0) / =VLOOKUP(B2:B5,Sheet2!A2:B5,2,0)
VLOOKUP will error if the value is not found (the way used above). It uses arguments like this:
=VLOOKUP(What you want to look up, where you want to look for it, the column number in the range containing the value to return, return an Approximate or Exact match – indicated as 1/TRUE, or 0/FALSE)
Office 365 has XLOOKUP which combines the logic of the two above and some more:
=XLOOKUP(A2:A5,Sheet1!A2:A5,Sheet1!B2:B5,"value not found",0)
XLOOKUP uses the following arguments:
=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])

Duplicating Data per number cycle

Im trying to duplicate data down a set of columns based on number cycle. Every time a number in sequence repeats, I'd like the number IM populating to increase by 1.
For example:
A
B
1
1
1
2
1
4
2
1
2
2
2
4
Every time column B repeats its cycle, In this case when it repeats back to 1, 2 ect. I'd like column A to increase by 1.
Initially I thought something like =IF(A3<>A2,B2+1,B2) would suffice, but that repeats.
Is there a different formula I can use to accomplish this?
Depending on your scenario, I'd do this.
These formulas need to originate in cell A2. If you're not working in the top left hand corner of your sheet, you'll need to adjust the formula accordingly.
Scenario 1 - All numbers in the sequence are unique.
=IF(INDIRECT(SUBSTITUTE(ADDRESS(1,B2),"1","") & "1") = B2, MAX($A$1:A1) + 1, MAX($A$1:A1))
Scenario 2 - All numbers in the sequence are NOT unique.
=IF(SUMIF($A$1:A1, MAX($A$1:A1), $A$1:A1) / 6 = MAX($A$1:A1), MAX($A$1:A1) + 1, MAX($A$1:A1))

Excel formula to find lowest value for duplicate values

This is probably quite simple for an Excel guru to solve but has driven me crazy for a few days. I have a large spreadsheet with duplicate race id's in column A and associated prices of runners in column I.There is a race id for every runner (hence duplicates) and a column H with a win/lose entry (1 or a 0) for each race. I am looking for a formula that will place a 1 in another column per respective row where the lowest price (Column I) was a winner (i.e.: where there is a 1 in column H) per race (race ID) i.e: looking for where the favourite won the race in each instance and have a 1 in the row/column next to that runner
e.g. data:
Column A
112335580
112335580
112335580
112335584
112335584
112335584
112335584
112335586
112335586
112335586
Column H
0,
1,
0,
0,
0,
1,
0,
0,
1
Column I
5.34,
2.34,
11.00,
7.34,
3.5,
2.89,
17.00,
12.00,
9.00,
5.25
I think I got close with INDEX + MATCH+ MIN and the odd COUNTIF :) (Pivot tables come close too but I don't know enough there either to solve it completely) but can't seem to crack it.An help appreciated. Thanks in advance
I tried to understand your requirement.
Based on this data:
Formula in D2:
=IF(AND(B2=MINIFS($B$2:$B$11,$A$2:$A$11,A2),C2=1),1,0)

Sum values based on first occurrence of other column using excel formula

Let's say I have the following two columns in excel spreadsheet
A B
1 10
1 10
1 10
2 20
3 5
3 5
and I would like to sum the values from B-column that represents the first occurrence of the value in A-column using a formula. So I expect to get the following result:
result = B1+B4+B5 = 35
i.e., sum column B where any unique value exists in the same row but Column A. In my case if Ai = Aj, then Bi=Bj, where i,j represents the row positions. It means that if two rows from A-column have the same value, then its corresponding values from B-column are the same. I can have the value sorted by column A values, but I prefer to have a formula that works regardless of sorting.
I found this post that refers to the same problem, but the proposed solution I am not able to understand.
Use SUMPRODUCT and COUNTIF:
=SUMPRODUCT(B1:B6/COUNTIF(A1:A6,A1:A6))
Here the step by step explanation:
COUNTIF(A1:A6, A1:A6) will produce an array with the frequency of the values: A1:A6. In our case it will be: {3, 3, 3, 1, 2, 2}
Then we have to do the following division: {10, 10, 10, 20, 5, 5}/{3, 3, 3, 1, 2, 2}. The result will be: {3.33, 3.33, 3.33, 20, 2.5, 2.5}. It replaces each value by the average of its group.
Summing the result we will get: (3.33+3.33+3.33) + 20 + (2.5+2.5=35)=35.
Using the above trick we can just get the same result as if we just sum the first element of each group from the column A.
To make this dynamic, so it grows and shrinks with the data set use this:
=SUMPRODUCT($B$1:INDEX(B:B,MATCH(1E+99,B:B))/COUNTIF($A$1:INDEX(A:A,MATCH(1E+99,B:B)),$A$1:INDEX(A:A,MATCH(1E+99,B:B))))
... or just SUMPRODUCT.
=SUMPRODUCT(B2:B7, --(A2:A7<>A1:A6))

Excel: Return a single value based on two references

I have two values that a person would enter information for in column B:
Spreadsheet Name: Info
A B
1 Level 2
2 Class Class 2
In a second spreadsheet within the Workbook, i have a data spreadsheet with various tables.
So when a person enters information in !InfoB2 data validation drop down, it would return the name of the table the formula should use to search for the value in the Data table that's level is related to !InfoB2.
Spreadsheet Name: Data
Table Name: Class 1
A B
1 Level BAB
2 --------------------
3 1 8
4 2 3
Table Name: Class 2
A B
1 Level BAB
2 --------------------
3 1 2
4 2 7
So when someone enters Level: 2, and Class2, i would like it to return the value in the BAB column, how can i do this?
Edit
As ghetto as this is, it feels like it's on the right track, however it's returning #VALUE!
VLOOKUP(B1,VLOOKUP(B2,Class,2,FALSE),2,FALSE)
Table Class
Table Name: Class
A B
1 Class Name Table Name
2 Class 1 Class1Table
3 Class 2 Class2Table
You could try the following formula:
=INDEX(INDIRECT(B2&"[#All]"), MATCH(B1,INDIRECT(B2&"[[#All],[Level]]"),0), 2)
This takes the value of B2 (Class2 note I removed the space since table names can't contain spaces) and concatenates it with [#All] so you get: Class2[#All] (this is the table reference). INDIRECT converts the text into a valid range.
INDIRECT(B2&"[[#All],[Level]]") similarly gives the range Class2[[#All],[Level]].
MATCH(B1,Class2[[#All],[Level]],0) gives the row number in which the value in B1 is found (i.e. gives the row in which 2 is found, meaning the result is 4)
=INDEX(Class2[#All], 4, 2) then returns the value from range Class2[#All] in the 4th row and 2nd column.
If I understand correctly you will want to use INDIRECT and/or the structured reference syntax for this one.
I don't have access to Excel at the moment so I can't check to see if this would work. I'll update this answer once I try some stuff out.

Resources