Excel | Index Match | - excel
I require your assistance on the following:
Lets say we got 3 different groups: (A,B,C)
And we have a few value ranges within each group:
(Eg. A has 0 - 100, 101 - 200 while B has 0 - 200, 201 - 400 and C has 0 - 300, 301 - 600.)
At the end, for each group that falls under whatever range they have, they will be assigned a final number.
(Eg.
[A,95] = 0.5 / [A,101] = 1.0
[B,95] = 1.5 / [B,205] = 3.0
[C,95] = 4.5 / [C,308] = 6.0)
Currently i have my index match formula as follows:
"=INDEX(finalnumber!F2:F29,MATCH(C11&C25,Group!A2:A29&valuerange!D2:D29,0))"
I keep getting a #N/A response.
I have also created an array table as follows:
enter image description here
Group Range Final Number
A 0 - 100 0.50
A 101 - 200 1.00
B 0 - 200 1.50
B 201 - 400 3.00
C 0 - 300 4.50
C 301 - 600 6.00
Pls help! Many thanks in advance!
You can use the following (you will need to tailor to your layout). I have assumed A and 95, for example, are in separate cells as you concatenate cells in your formula to do your lookup.
=IF(AND(ISERROR(INDEX(OFFSET(INDEX(C:C,H2),,,I2-H2+1,1),MATCH(VLOOKUP(G2,LEFT(OFFSET(INDEX(B:B,H2),,,I2-H2+1,1),FIND("-",OFFSET(INDEX(B:B,H2),,,I2-H2+1,1))-1)*1,TRUE),LEFT(OFFSET(INDEX(B:B,H2),,,I2-H2+1,1),FIND("-",OFFSET(INDEX(B:B,H2),,,I2-H2+1,1))-1)*1,0))),INDEX(A:A,COUNTA(A:A)+1)=F2,G2>=1*LEFT(INDEX(B:B,COUNTA(A:A)+1),FIND("-",INDEX(B:B,COUNTA(A:A)+1))-1),G2<=1*RIGHT(INDEX(B:B,COUNTA(A:A)+1),LEN(INDEX(B:B,COUNTA(A:A)+1)) - FIND("-",INDEX(B:B,COUNTA(A:A)+1)))),INDEX(C:C,COUNTA(A:A)+1),INDEX(OFFSET(INDEX(C:C,H2),,,I2-H2+1,1),MATCH(VLOOKUP(G2,LEFT(OFFSET(INDEX(B:B,H2),,,I2-H2+1,1),FIND("-",OFFSET(INDEX(B:B,H2),,,I2-H2+1,1))-1)*1,TRUE),LEFT(OFFSET(INDEX(B:B,H2),,,I2-H2+1,1),FIND("-",OFFSET(INDEX(B:B,H2),,,I2-H2+1,1))-1)*1,0)))
This is entered as an array formula with Ctrl+ Shift+ Enter
Formulas in helper cells (to keep overall formula more legible):
H2 is =MATCH(F2,A:A,0) ' finds the first match for the letter e.g. A
I2 is =MAX(IF(A:A=F2,ROW(A:A)-ROW(INDEX(A:A,1,1))+1)) ' finds the last match for the letter e.g. A. This is entered with Ctrl+ Shift+ Enter i.e. an array formula.
Data layout
Example run:
Notes:
You might want to wrap the whole thing in an IFERROR( formula, "") to hide any not found error messages.
I'm unclear why you require four separate worksheets for this operation. For simplicity in demonstrating, I've put your lookup table on the same worksheet as the values to lookup.
=SUMPRODUCT(I$2:I$7, (G$2:G$7=LEFT(A2))*(--REPLACE(H$2:H$7, FIND(" - ", H$2:H$7), 9, TEXT(,))<=--MID(A2, 3, 9))*
(--REPLACE(H$2:H$7, 1, FIND(" - ", H$2:H$7)+1, TEXT(,))>=--MID(A2, 3, 9)))
Related
Sum of the greatest value in one column, plus the sum of the other values in another column
Consider the following sheet/table: A B 1 90 71 2 40 25 3 60 16 4 110 13 5 87 82 I want to have a general formula in cell C1 that sums the greatest value in column A (which is 110), plus the sum of the other values in column B (which are 71, 25, 16 and 82). I would appreciate if the formula wasn't an array formula (as in requiring Ctrl + Shift + Enter). I don’t have Office 365, I have Excel 2019. My attempt Getting the greatest value in column A is easy, we use MAX(A1:A5). So the formula I want in cell C1 should be something like: =MAX(A1:A5) + SUM(array_of_values_to_be_summed) Obtaining the values of the other rows in column B (what I called array_of_values_to_be_summed in the previous formula) is the hard part. I've read about using INDEX, MATCH, their combination, and obtaining arrays by using parenthesis and equal signs, and I've tried that, without success so far. For example, I noticed that NOT((A1:A5 = MAX(A1:A5))) yields an array/list containing ones (or TRUEs) for the relative position of the rows to be summed, and containing a zero (or FALSE) for the relative position of the row to be omitted. Maybe this is useful, I couldn't find how. Any ideas? Thanks. Edit 1 (solution) I managed to obtain what I wanted. I simply multiplied the array obtained with the NOT formula, by the range B1:B5. The final formula is: =MAX(A1:A5) + SUM(NOT((A1:A5 = MAX(A1:A5))) * B1:B5) Edit 2 (duplicate values) I forgot to explain what the formula should do if there are duplicates in column A. In that case, the first term of my final formula (the term that has the MAX function) would be the one whose corresponding value in column B is smallest, and the value in column B of the other duplicates would be used in the second term (the one containing the SUM function). For example, consider the following sheet/table: A B 1 90 71 2 110 25 3 60 16 4 110 13 5 110 82 Based on the above table, the formula should yield 110 + (71 + 25 + 16 + 82) = 304. Just to give context, the reason I want such a formula is because I’m writing a spreadsheet that automatically calculates the electric current rating of the short-circuit protective device of the feeder of a group of electric motors in a house or building or mall, as required by the article 430.62(A) of the US National Electrical Code. Column A is the current rating of the short-circuit protective device of the branch-circuit of each motors, and column B is the full-load current of each motor.
You can use this formula =MAX(A1:A5) +SUM(B1:B5) -AGGREGATE(15,6,(B1:B5)/(A1:A5=MAX(A1:A5)),1) Based on #Anupam Chand's hint for max-value-duplicates there could also be min-value-duplicates in column B for corresponding max-value-duplicates in column A. :) This formula would account for that =SUM(B1:B5) +(MAX(A1:A5)-AGGREGATE(15,6,(B1:B5)/(A1:A5=MAX(A1:A5)),1)) *SUMPRODUCT((A1:A5=MAX(A1:A5))*(B1:B5=AGGREGATE(15,6,(B1:B5)/(A1:A5=MAX(A1:A5)),1))) Or with #Anupam Chand's shorter and better readable and overall better style :) =SUM(B1:B5) +(MAX(A1:A5)-MINIFS(B1:B5,A1:A5,MAX(A1:A5))) *COUNTIFS(A1:A5,MAX(A1:A5),B1:B5,MINIFS(B1:B5,A1:A5,MAX(A1:A5))) The explanation works for bot solutions: The SUM-part just sums the whole list. The second line gets the max-value for column A and the corresponding min-value of column B for the max-values in column A and adds or subtracts it respectively. The third line counts, how many times the corresponding min-value for the max-value occurs and multiplies it with the second line.
Can you try this ? =MAX(A1:A5)+SUM(B1:B5)-MINIFS(B1:B5,A1:A5,MAX(A1:A5)) What we're doing is adding the max of A to all rows of B and then subtracting the min value of B where A is the max.
If you have Excel 365 you can use the following LET-Formula =LET(A,A1:A5, B,B1:B5, MaxA,MAX(A), MinBExclude, MINIFS(B,A,MaxA), sumB1,SUMPRODUCT(B*(A=MaxA)*(B<>MinBExclude)), sumB2,SUMPRODUCT(B*(A<>MaxA)), MaxA +sumB1+sumB2 A and B are shortcuts for the two ranges MaxA returns the max value for A (110) MinBExclude filters the values of column B by the MaxA-value (25, 13, 82) and returns the min-value of the filtered result (13) sumB1 returns the sum of the other MaxA values from column B (26 + 82) sumB2 returns the sum of the values from B where value in A <> MaxA (71 + 60) and finally the result is returned If you don't have Excel 365 you can add helper columns for MaxA, MinBExclude, sumB1 and sumB2 and the final result
Increment a number within a formula by 2 each time
As in this image: I have the following formula in merged cellset F229:F231, which works correctly: =OFFSET('Food Diary'!$A$2,31*(ROWS($F$18:F229)-3),) This pulls data from another worksheet - in this case the value 73.0 is pulled (there are similar formulas in the cell range H229 to M231. Essentially I want the -3 part at the end of above OFFSET formula to increment by two each time I copy and paste the three row set. So in the merged cellset of F232 - F234 it would be -5 and in the next one it would be -7, then -9 etc. It's a bit of a hack but this would result in the correct data being pulled. This is not a work spreadsheet, just a personal log to record my food etc so doesn't have to be ideal.
Change -3 to +2*Row()/3 + c, where c is a modifier to ensure that your first row lines up For example, if the first row is line 4, and you want the value to be 2: - 2 * Row() / 3 + c - 2 * 4 / 3 + c - 8 / 3 + c - 2.666 + c c = - 1/3 - 2.666 - 1/3 - 3 - 2 * Row() / 3 - 1/3 Then, when you copy it down to Row 7: - 2 * Row() / 3 - 1/3 - 2 * 7 / 3 - 1/3 - 14 / 3 - 1/3 - 4.666 / 3 - 1/3 - 5
Use one of the following formula for your counter starting at -3 and changing by -2 every three rows. You can either start using row A1 or you can reference your current cell and make some adjustments to the formula to achieve the same result. =-3-2*(ROUNDUP(ROW(A1)/3,0)-1) or =-3-2*(ROUNDDOWN((ROW(G229)-ROW($G$229))/3,0)) both will work for generating the number you are looking for Your final formula might look like: =OFFSET('Food Diary'!$A$2,31*(ROWS($F$18:F229)+(-3-2*(ROUNDUP(ROW(A1)/3,0)-1))),)
Using SUMIFS to sum all rows matching one criteria within a column matched by another criteria
I think I'm very close to what I want but I'm still getting an #N/A error - I have some wage sheets that cross reference a labour table 'Table1' which stores the information of my employees (Pay code, Site, Contracted Hours etc). In Table1 I have columns titled 1-10 which values. On the wage sheet I have a cell 'AM3' that will be a number between 1-10. Depending on that cell, the cell below should sum up all values in that column for all staff at that particular site. For example - I have a wage sheet for site 'EXAMPLE SITE' which is stored in cell C2 and cell AM3 = 9. I am trying to use the following formula to make this work: =SUMIFS(INDEX(Table1,,MATCH(AM3,Table1[#Headers]),0),Table1[[Site]:[Site]],$C$2) That is, I'm checking Table1, and finding the column headed with the value contained in cell AM3 (with an exact match). criteria_range1 is the Site column and criteria1 is 'EXAMPLE SITE' stored in C2. I would expect this to sum every cell in column header 9, matching Site 'EXAMPLE SITE'. But I just get the #N/A error. Table1: Name - Site - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 Tom - EXAMPLE SITE - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 10 - 20 Geoff- EXAMPLE SITE - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 9 - 18 Sarah- RANDOM SITE - 0 - 0 - 0 - 0 - 0 - 0 - 5 - 15 - 25 - 40 With that example I want the formula to return '19' as a numerical value. I feel like I'm just being dumb but no amount of googling is helping me.
MATCH seems to be having a hard time with matching table headers with numeric values. Try this: =SUMIFS(INDEX(Table1,,MATCH(AM3,INDEX(Table1[#Headers]*1,),0)),Table1[[Site]:[Site]],$C$2)
Same problem with MATCH as earlier but alternate resolution. =SUMIFS(INDEX(Table1[[1]:[10]],0,MATCH(TEXT(AM3, "0"),Table1[[#Headers],[1]:[10]],0)),Table1[Site],C2)
excel formula to filter range based on criteria
I have a strange problem I've been trying to find a good solution to for the past few hours. I have a table in excel similar to the following: |A B C D E F -----+-----+-----+-----+-----+-----+----- 1 |2011 1 0 -5 4 2 2 |2011 2 1 1.2 2 3 3 |2011 3 1 2 4 -4 4 |2011 0 1 -3 3 -2 5 |2012 5 1 0 0 1 6 |2012 0 1 0.25 0 0 the data falls into different categories based on columns A-C, with columns D-F being dollar amounts. What I'm trying to figure out is, is there a way to return the max absolute value of columns D-F for a subset of these rows using the values in columns A-C as filter values? Now, I know how to return the max absolute value of a range: =max(abs(START:END)), but what I don't know how to do is filter out some of the rows from the range based on their column A-C values. Perhaps a specific example of what I'm looking for: How would I get the range D-F where: A=2011 B<>0 C=1 For the above set of conditions and data, the answer I'd like to have returned is 4, from E3. I am not opposed to adding helper columns within reason, but there are many more sets of filter conditions, which was the undoing of a few other solutions I cobbled together; 16-32 helper columns would not be accepted by the group I'm trying to develop this for.
If your excel version supports the newer MAXIFS function, use that with the ABS function and MINIFS function. =max(maxifs(d:f, a:a, 2011, b:b, "<>", c:c, 1), abs(minifs(d:f, a:a, 2011, b:b, "<>", c:c, 1))) If not then AGGREGATE will provide the conditions. =AGGREGATE(14, 6, ABS(D1:F6)/((A1:A6=2011)*(B1:B6<>0)*(C1:C6=1)), 1)
Excel split given number into sum of other numbers
I'm trying to write formulae that will split a given number into the sum of 4 other numbers. The other numbers are 100,150,170 and 200 so the formula would be x = a*100+b*150+c*170+d*200 where x is the given number and a,b,c,d are integers. My spreadsheet is set up as where col B are x values, and C,D,E,F are a,b,c,d respectively (see below). B | C | D | E | F | 100 1 0 0 0 150 0 1 0 0 200 0 0 0 1 250 1 1 0 0 370 0 0 1 1 400 0 0 0 2 I need formulae for columns C,D,E,F (which are a,b,c,d in the formula) Your help is greatly appreciated.
UPDATE: Based on the research below, for input numbers greater than 730 and/or for all actually divisible input numbers use the following formulas: 100s: =CHOOSE(MOD(ROUNDUP([#number]/10;0); 20)+1; 0;1;1;0;1;1;0;1;0;0;1;0;0;1;0;0;1;0;1;1) 150s: =CHOOSE(MOD(ROUNDUP([#number]/10;0); 10)+1; 0;0;1;1;0;1;1;0;0;1) 170s: =CHOOSE(MOD(ROUNDUP([#number]/10;0); 5)+1; 0;3;1;4;2) 200s: =CEILING(([#number]-930)/200;1) + CHOOSE(MOD(ROUNDUP([#number]/10;0); 20)+1; 4;1;2;0;2;3;1;3;1;2;4;2;3;0;2;3;0;3;0;1) MOD(x; 20) will return numbers 0 - 19, CHOOSE(x;a;b;...) will return n-th argument based on the first argument (1=>second argument, ...) see more info about CHOOSE use , instead of ; based on your Windows language®ion settings let's start with the assumption that you want to preferably use 200s over 170s over 150s over 100s - i.e. 300=200+100 instead of 300=2*150 and follow the logical conclusions: the result set can only contain at most 1 100, at most 1 150, at most 4 170s and unlimited number of 200s (i started with 9 170s because 1700=8x200+100, but in reality there were at most 4) there are only 20 possible subsets of (100s, 150s, 170s) - 2*2*5 options 930 is the largest input number without any 200s in the result set based on observation of the data points, the subset repeats periodically for number = 740*k + 10*l, k>1, l>0 - i'm not an expert on reverse-guessing on periodic functions from data, but here is my work in progress (charted data points are from the table at the bottom of this answer) the functions are probably more complicated, if i manage to get them right, i'll update the answer anyway for numbers smaller than 740, more tweaking of the formulas or a lookup table are needed (e.g. there is no way to get 730, so the result should be the same as for 740) Here is my solution based on lookup formulas: Following is the python script i used to generate the data points, formulas from the picture and the 60-row table itself in csv format (sorted as needed by the match function): headers = ("100s", "150s", "170s", "200s") table = {} for c200 in range(30, -1, -1): for c170 in range(9, -1, -1): for c150 in range(1, -1, -1): for c100 in range(1, -1, -1): nr = 200*c200 + 170*c170 + 150*c150 + 100*c100 if nr not in table and nr <= 6000: table[nr] = (c100, c150, c170, c200) print("number\t" + "\t".join(headers)) for r in sorted(table): c100, c150, c170, c200 = table[r] print("{:6}\t{:2}\t{:2}\t{:2}\t{:2}".format(r, c100, c150, c170, c200)) __________ =IF(E$1<740; 0; INT((E$1-740)/200)) =E$1 - E$2*200 =MATCH(E$3; table[number]; -1) =INDEX(table[number]; E$4) =INDEX(table[100s]; E$4) =INDEX(table[150s]; E$4) =INDEX(table[170s]; E$4) =INDEX(table[200s]; E$4) + E$2 __________ number,100s,150s,170s,200s 940,0,0,2,3 930,1,1,4,0 920,0,1,1,3 910,0,0,3,2 900,1,0,0,4 890,0,1,2,2 880,0,0,4,1 870,1,0,1,3 860,0,1,3,1 850,1,1,0,3 840,1,0,2,2 830,0,1,4,0 820,1,1,1,2 810,1,0,3,1 800,0,0,0,4 790,1,1,2,1 780,1,0,4,0 770,0,0,1,3 760,1,1,3,0 750,0,1,0,3 740,0,0,2,2 720,0,1,1,2 710,0,0,3,1 700,1,0,0,3 690,0,1,2,1 680,0,0,4,0 670,1,0,1,2 660,0,1,3,0 650,1,1,0,2 640,1,0,2,1 620,1,1,1,1 610,1,0,3,0 600,0,0,0,3 590,1,1,2,0 570,0,0,1,2 550,0,1,0,2 540,0,0,2,1 520,0,1,1,1 510,0,0,3,0 500,1,0,0,2 490,0,1,2,0 470,1,0,1,1 450,1,1,0,1 440,1,0,2,0 420,1,1,1,0 400,0,0,0,2 370,0,0,1,1 350,0,1,0,1 340,0,0,2,0 320,0,1,1,0 300,1,0,0,1 270,1,0,1,0 250,1,1,0,0 200,0,0,0,1 170,0,0,1,0 150,0,1,0,0 100,1,0,0,0 0,0,0,0,0
Assuming that you want as many of the highest values as possible (so 500 would be 2*200 + 100) try this approach assuming the number to split in B2 down: Insert a header row with the 4 numbers, e.g. 100, 150, 170 and 200 in the range C1:F1 Now in F2 use this formula: =INT(B2/F$1) and in C2 copied across to E2 =INT(($B2-SUMPRODUCT(D$1:$G$1,D2:$G2))/C$1) Now you can copy the formulas in C2:F2 down all columns That should give the results from your table