Excel - Identify a value in one sheet vs values in another with different ranges - excel

I need some help with an excel formula or format that can help me with the following:
TABLE 1
(Row) |(a) ID | (b)FROM | (c) TO | (d) VALUE
(1) 123 0 1 50
(2) 123 1 2 50
(3) 123 2 3 50
(4) 123 3 4 50
(5) 123 4 5 60
(6) 123 5 6 60
TABLE 2
(Row) |(a) ID | (b)FROM | (c) TO | (d) VALUE
(1) 123 0 4 50
(2) 123 4 6 60
So table one has been incremented to 1 (from and to) whereas table two contains ranges with the values. The incremented values in table 1 should equal the values in table two if the range in table one falls within the range from table 2.
OUTPUT
(Row) |(a) ID | (b)FROM | (c) TO | (d) VALUE
(1) 123 0 1 50 TRUE
(2) 123 1 2 50 TRUE
(3) 123 2 3 50 TRUE
(4) 123 3 4 50 TRUE
(5) 123 4 5 60 TRUE
(6) 123 5 6 60 TRUE
Basically ID'123' has a value of 50 for the increments from 0 to 4 and value of 60 for the increments from 4 – 6 and as per TABLE 2 0-4 = 50 and 4-6 = 60 therefore the statement should be TRUE.
=IF(AND(A1=table2!a:a, table1!B1>=table2!b:b,table1!a1<table!B:B),IF(table1!d2=table2!d:d, TRUE,FALSE))
It might be with the way excel deals with ranges etc?

I like the answer from #tigeravatar (credits to him/her) but if you haven't got a ordered list I have created something below that doesn't need that. If table two is not ordered by ID number you could use this formula in cell E2 and copy down:
=IFERROR(IF(B2>=INDEX(table2!$A:$D,MATCH(D2,table2!$D:$D,0),2),IF(C2<=INDEX(table2!$A:$D,MATCH(D2,table2!$D:$D,0),3),IF(A2=INDEX(table2!$A:$D,MATCH(D2,table2!$D:$D,0),1),TRUE,FALSE))),FALSE)
This does essentially the same but with an AND statement
=IFERROR(IF(AND(A2=INDEX(table2!$A:$D,MATCH(D2,table2!$D:$D,0),1),B2>=INDEX(table2!$A:$D,MATCH(D2,table2!$D:$D,0),2),C2<=INDEX(table2!$A:$D,MATCH(D2,table2!$D:$D,0),3)),TRUE,FALSE),FALSE)

On table1, cell E2, use this formula and copy down:
=D2=VLOOKUP(B2,INDEX(table2!B:B,MATCH(A2,table2!A:A,0)):INDEX(table2!D:D,MATCH(A2,table2!A:A,0)+COUNTIF(table2!A:A,A2)-1),3)

Related

Finding a formula to compute partial sums for consecutive rows that satisfy a condition

How do I do this is excel. The example is provided below. If we don't sell any products on a specific day I would like to move those hours to the next date.
If you need to compute partial sums of Hours for all the consecutive rows between rows that satisfy the condition that the value Sold is greater than zero, you could do this with an auxiliary column
A B C D
---------------------------------
1 |Hours Sold Sums Solution
2 | 300 30 300 300
3 | 30 0 300 0
4 | 0 0 300 0
5 | 30 0 300 0
6 | 300 50 660 360
7 | 23 0 660 0
8 | 100 25 783 123
Here Sums is defined by a formula for C2
=IF(B2>0,SUM(A2:$A$2),C1)
You can automatically populate the cells below.
This formula puts in a cell a partial sum of Hours up to the current row if Sold is nonzero, otherwise copies the previous partial sum of hours. We need this to subtract this value on the next step.
When you have the column C filled, it is sufficient to put the following formula in D2 and populate the cells below
=IF(ROW(B2)>2,IF(B2>0,C2-C1,0),C2)
This formula handles correctly both D2 that does not have a preceding row with values and the remaining cells in column D.
In fact you could combine the two formulas together and avoid the need to have an auxiliary column. Put the following formula in C2 and spread it down to the rest of the cells in column C
=IF(ROW(B2)>2,IF(B2>0,SUM(A2:$A$2)-SUM(C1:$C$2),0),A2)
to get
A B C
---------------------------------
1 |Hours Sold Solution
2 | 300 30 300
3 | 30 0 0
4 | 0 0 0
5 | 30 0 0
6 | 300 50 360
7 | 23 0 0
8 | 100 25 123

Excel Multiply one set of values with given matrix and sum results

I need to redistribute values for Old entries by using new distribution in a given table.
Example:
Need to redistribute using given % in this table:
So New Value of Element 1 = 99% * old1 + 7% * old2 + 3% * old3 + 26% * old5
This is not whole table, it is pretty large. There must be a simpler way than adding things up manually.
You can use the MMULT() worksheet function for that.
Example:
A B C D E F
1 Amount
2 100
3 200
4 500
5 400
6
7 Percentages 1 2 3 4
8 99 7 3 26 =MMULT(B8:E8;A$2:A$5)/100
9 1 93 34 0 =MMULT(B9:E9;A$2:A$5)/100
10 0 0 63 74 =MMULT(B10:E10;A$2:A$5)/100
For your information: I've entered the first formula in F8, and dragged and dropped until F10.

excel match index if exists

I have 2 excel sheets:
Sheet1: (Value = Prevalue)
Id Preval Value
111 1 1
123 2 2
100 3 3
Sheet2:
Id Num Date
111 5
123 6 1/1/18
100 7
I want to perform a logic saying that: Matching the 2 sheets by Id, if Date on sheet2 exists then Value on sheet1 = num on sheet2 else = Prevalue
Id Value
111 1 (same)
123 6 (update since date exists)
100 3 (same)
How would this be done using index or vlookup? Many thanks!
Try this formula:
=IF(VLOOKUP(A2,Sheet2!$A$1:$C$4,3,0)="",B2,VLOOKUP(A2,Sheet2!$A$1:$C$4,2,0))

Excel multiple search/match and sum (edit: answered with SUMIFS, COUNTIFS)

I am looking for help to solve this excel problem.
Essentially I want to create a formula for cells in column F which does a multiple search on 3 criteria (on cells in columns A,B,C) and want to access the corresponding column D values where all these (multiple) matches occur, and sum this in column F. I'd also like a count of the amount of matches found to calculate the value in column F; placed alongside in column G.
e.g.
IF col_A_value (anywhere in whole A column) = current_col_A_value +/- 1
AND col_B_value (anywhere in whole B column) = current_col_B_value +/- 1
AND col_C_value (anywhere in whole C column) = current_col_C_value - 1
THEN (output in column F) the sum of all values from row D where this criteria is met
(also, as a seperate but related cell formula, output in column G) the total Count of times this occurs.
Note: the values in columns A,B,C are all integars and the +/- above means to search for any values which are either +1, 0, or -1 different in value. (i.e. this includes the value itself).
e.g. If the value in cell A1 = 10, B1 = 45, C1 = 881, then the first search criteria would look for all other rows with values of 9, 10 or 11 in column A. Then based on these rows, the second search criteria would refine the search to only those rows which also include either a 44, 45 or 46 in column B, and the third search criteria would refine the search again to only include those rows where the column C value is 880.
Next, the values in the column D cells from all of these 'filtered' rows would be summed and the result placed in the column F cell. (The count of these results rows would be put in column G. (seperate formula required))
Since these are all unique entries (think of columns A,B,C creating unique vector coordinates in space), there should be a maximum of 9 entries found and summed. A +/-1: 3 variations, B +/-1: 3 variations and C -1 only: 1 variation. In total: 3x3x1 = 9 unique rows maximum (and potentially none as a minimum, as in the below example).
(If no match is found a value of 0 is good.)
Example with A,B,C,D and E as given values, and column F values calculated (together with the count shown in col G):
A B C D E F G
1 1 1 90 8 0 0
1 2 1 80 6 0 0
1 3 1 70 1 0 0
1 4 1 60 6 0 0
2 1 1 50 1 0 0
2 2 1 40 8 0 0
2 3 1 30 6 0 0
2 4 1 20 8 0 0
3 1 1 10 8 0 0
3 2 1 11 6 0 0
3 3 1 12 1 0 0
3 4 1 13 1 0 0
1 1 2 99 8 260 4
1 2 2 89 6 360 6
1 3 2 79 1 300 6
1 4 2 69 6 180 4
2 1 2 59 1 281 6
2 2 2 49 8 393 9
etc
To illustrate how column F values are calculated here is the working:
260 = 90+80+50+40
360 = 90+80+70+50+40+30
300 = 80+70+60+40+30+20
180 = 70+60+30+20
281 = 90+80+50+40+10+11
393 = 90+80+70+50+40+30+10+11+12
Thanks a lot for any help with this!
These formulas should do what you desire:
F1: =SUMIFS(D:D,A:A,"<="&A1+1,A:A,">="&A1-1,B:B,"<="&B1+1,B:B,">="&B1-1,C:C,C1-1)
G1: =COUNTIFS(A:A,"<="&A1+1,A:A,">="&A1-1,B:B,"<="&B1+1,B:B,">="&B1-1,C:C,C1-1)
The formulas can simply be copied down as you need them...
(Still I don't know what col E is for)

Paste subsequent values in excel with condition

I have data in an Excel sheet as:
Column A Column B
1 1
5 5
6 6
50 50
.. 51
.. 52
.. 53
1 1
5 2
6 6
50 50
.. 51
.. 52
.. 53
very long list
I want to fill Column B corresponding to Column A as shown above that if cell A is not blank then cell B will have same value as A ..and if Cell A has value 50, then next blank rows in column B will have subsequent values after 50 ..
I tried to make formula
=IF(A2="",IF(A2=50,50,VALUE(A1)+1),A2)
and pasted in Cell B2 and dragged but it is giving me wrong results:
5
6
50
51
1
1
..
Can anyone please suggest? Thanks in advance.
This assumes your data starts in row 2. Paste in B2 and fill down.
=IFERROR(IF(A2<>"",A2,IF(OR(AND(A2=50,A3=""),B1>=50),1+B1,"")),"")
This works on your use case, but it's all kinds of kludgy so might not extend well to other cases.
You can simply paste in B2
=IF(ISBLANK(A2),B1+1,A2)
and then copy the formula by dragging it down
Outcome:
A B
---------
1 1
5 5
6 6
50 50
51
52
53
1 1
5 5
6 6
50 50
51
52
53
Note: it won't work for B1. You have to have enter a value in this cell manually.

Resources