Excel Sumifs searching first 8 characters of a column - excel

Good evening all,
I want to do a sumifs() but the two columns do not always have the exact same values. However, the first 8 characters would always match in both columns. For example the value I wish to look up is "00123456 - Nice Salad". The data I wish to search in sits in Column A with value to return in Column B.
I know I can use the left() function on the value to lookup but I am unsure how best to search against just the first 8 characters in column A. I would like the formula to return the number 6 from column B in this example.
Current formula is as follows: =sumifs(left(00123456 - Nice Salad,8),A:A,B:B)
I hope this all makes sense and any help is appreciated.
Many thanks, Alan.

Screenshot/this sheet refer:
One way is with a regular sum equation:
=SUM(1*(LEFT(A2:A4,8)=E2)*(B2:B4))
However, this can be computationally intensive (i.e. if you have plenty of data/rows to evaluate). The better, in my view, is simply a sumifs with wildcard '*', i.e.:
=SUMIFS(B2:B4,A2:A4,E2&"*")

Related

Find a value in a range (any of multiple column or rows) and return the value in far left most column of that row

Looking for something like a typical index match formula that can look to the right and return value to the left, but look at all columns in a range. Take below valid formula for example.
(Excel 2021.)
Finds A1's value in column D, and it returns value from column C.
=INDEX($C$1:$C$10,MATCH(A1,$D$1:$D$10,0))
In my ideal world I can Keep $D$1 and change $D$10 to $F$10 so it searches all columns D/E/F, and still returns C like below. However that does not work in our real world, any other ideas please? Thanks!
=INDEX($C$1:$C$10,MATCH(A1,$D$1:$F$10,0))
Update*
To clarify there are mix of letters and numbers. Also this table will be about 50k rows so hoping as simple as possible.
Also Column C will all be unique for sure, and D-F should be unique values but there is a chance a mistake and a few duplicates might be in.
You need MMUL() with INDEX(). Try below formula if you have Excel-365.
=FILTER(C1:C10,MMULT(--(D1:F10=A1),SEQUENCE(COLUMNS(D1:F1))))
For older version try
=INDEX($C$1:$C$10,LARGE(MMULT(--($D$1:$F$10=A1),TRANSPOSE({1,1,1}))*ROW($C$1:$C$10),1))
Since your INDEX/MATCH take from the same rows, you can first simplify your original search with
=XLOOKUP(A1,$D$1:$D$10,$C$1:$C$10)
XLOOKUP combines HLOOKUP and VLOOKUP with exact match being the default.
This will work for searching three rows
IFERROR(IFERROR(XLOOKUP(A1,$D$1:$D$10,$C$1:$C$10), XLOOKUP(A1,$E$1:$E$10,$C$1:$C$10)), XLOOKUP(A1,$F$1:$F$10,$C$1:$C$10))
We can name the columns colC, colD, colE, and colF and it becomes
IFERROR(IFERROR(XLOOKUP(A1,colD,colC), XLOOKUP(A1,colE,colC)), XLOOKUP(A1,colF,colC))
As with other lookups, this returns the first value or #N/A error.
This could be made more scalable for higher number of rows if we are allowed to add a column somewhere.

use search, find and replace text from one work sheet to other sheet in excel

I am not an expert in Excel but I have been using the format.
I am trying to make a roster of my staff in Excel sheet using formulas.
The 1st sheet I have uses the row name TIME as a priority and fills other columns with staff names.
Now in the 2nd sheet, I want to use a formula in each staff ROW and the column automatically fills with the TIME at each name.
Please help me if possible.
Thank you.
Use INDEX / MATCH combo. Something like this:
=IFERROR(INDEX(Sheet1!$B$3:$B$9,MATCH($A2,Sheet1!C$3:C$9,0)),"OFF DAY")
Syntax:
=INDEX(rng,index_number) — returns the value based on the index number
=MATCH(lookup_value,rng) — returns the relative position of the lookup value
=INDEX(rng,MATCH(lookup_value,rng)) — we know all the arguments except for one — index_number. Since the output of MATCH function is the same as the index_number, we're going to substitute the index_number with MATCH function.
You can almost think of the INDEX/MATCH combo as:
=INDEX/MATCH(rng,search_value)
=IFERROR(value_or_expression_to_evaluate,value_to_return_if_error) — and finally, we're going to wrap our formula with this one, which will return a value if there is no match, which means, in your example, employee is on-leave, on a rest-day, or whatever. Can be =IFNA, too.
Now, to return all values with multiple matched lookup_value just like in your example, where "Tam" have two shifts on Monday, you may use a trailing number with employee names, i.e. "Tam1" and "Tam2" to indicate the number of shift in a given day. Or you may also use a combination of COUNTIF function (to count the number of shift of "Tam") and CONCATENATE to join the results together so that the output is gonna be: 630-1430 / 1230-2200. There are many ways to do it depending on your requirement.
Hope this helps..

Taking average of certain values in one Excel column based on values in another

I have a (large) array of data in Excel of which I need to compute the average value of certain values in one column, based on the values of another column. For example, here's a snippet of my data:
So specifically, I want to take the average of the F635 mean values corresponding with Row values of 1. To take it a step further, I want this to continue to Row values of 2, Row values of 3 etc.
I'm not familiar with how to run code in Excel but have attempted to solve this by using the following:
=IF($C = "1", AVERAGE($D:$D), "")
which (to my understanding) can be interpreted as "if the values (anywhere) in column C are equal to 1, then take the average of the corresponding values in column D."
Of course, as I try this I get a formula error from Excel.
Any guidance would be incredibly appreciated. Thanks in advance.
For more complicated cases, I would use an array-formula. This one is simple enough for the AVERAGEIF formula. For instance =AVERAGEIF(A1:A23;1;B1:B23)
Array-formula allows for more elaborate ifs. To replicate the above, you could do =SUM(IF($A$1:$A$23=1;$B$1:$B$23;0))/COUNT(IF($A$1:$A$23=1;$B$1:$B$23;0)).
Looks like more work but you can create extremely elaborate if-statements. Instead of hitting ENTER, do CTRL-ENTER when entering the formula. Use * between criteria to replicate AND or + for OR. Example: SUM(IF(($A$1:$A$23="apple")*($B$1:$B$23="green");$C$1:$C$23;0)) tallies values for green apples in c1:c23.
Your sample data includes three columns with potential ifs so my guess is that you're going to need array formulas at some point.
Excel already has a builtin function for exactly this use; AVERAGEIF().
=AVERAGEIF(C:C,1,D:D)

Excel search and return

So, I have an Excel-file with two sheets. The first sheet contains 7 Columns of different values.
The second sheet contains a list of special customer prices.
What i want to do, is basicly search for the value given in e.g. cell A2, in Sheet2!A:A. If i were to find this value (it's a text value), I want to return the value located in that spesific row containing the value searched for, only 3 colums to the right.
I've done a lot of experiments, but really can't get INDEX and MATCH to do the work properly for me. Anyh suggestions?
Feel free to ask for more information, as I know I can be a challange to understand..
Best regards
try offset() and match(), offset(reference,rows,cols). use match to find the number of rows or columns to move from the reference point.
Using OFFSET is against almost all best practice guides. It is a volatile function, meaning it should be avoided at all costs. Use INDEX+MATCH instead. It can do all the same stuff but has much better performance.
=INDEX(column holding the value you want to return, match to find row #, 1)
=MATCH(value you are looking for, column you are searching in, 0 means exact match)
Result:
=INDEX(Sheet2!$D$2:$D$10,MATCH(A2,Sheet2!$A$2:$A$10,0),1)
I believe the function you are looking for is a vlookup. Try this:
=vlookup(A2, Sheet2!A:D, 4, 0)
Regards,
Windyvation

Returning a value if three columns match in excel

I have two excel sheets where I need to match three values to return a fourth. The similar columns are month, agent, and subdomain. The fourth column is called difference.
Concatenate would work, as per #MakeCents suggestion, but if you don't want a helper column, SUMPRODUCT would work.
example:
=SUMPRODUCT(--(A2:A12="d"),--(B2:B12="S"),--(C2:C12="Apr"),D2:D12)
would search range A2:A12 for "d", B2:B12 for "S" and C2:C12 for "Apr", and return the value fom D2:D12 that corresponds to where all 3 are true. If multiple lines match, it will add the value in D2:D12 for all matching rows.
The -- is used to change the True/False results into 0 and 1 for use in multiplication
Limitations of SUMPRODUCT
Recommended to specify the range explicitly; it will be slower with just
column references
(A1:A4000 is ok, A:A is not)
It will return an error if any of the values are errors
It will return numeric results only - text is evaluated as Zero
Although I believe #MakeCents comment / suggestion on how to do this is the way I would go since it is the simplest, you could accomplish this a different way (MUCH more processor-intensive, though) using the Index() and Match() functions and Array formulas.
For example, suppose your 3 columns of data you're looking to match against are columns A-C and you're looking to return the matching value from column D in Sheet1
Now, the 3 values you're looking to have matched are in cells A1, B1 & C1 of Sheet2, you could use the following formula:
=INDEX(Sheet1!D:D,MATCH(1,(Sheet1!A:A=A1)*(Sheet1!B:B=B1)*(Sheet1!C:C=C1),0))
And ENTER IT AS AN ARRAY FORMULA by pressing Ctrl + Shift + Enter
Hope this helps!
You are looking for a Lookup with multiple criteria.
One of the most robust options is
=INDEX(D:D,SUMPRODUCT(--(A:A="d"),--(B:B="S"),--(C:C="Apr"),ROW(D:D)),0)
It does not need to be entered as an array formula.
Taken from [1] (blogs.office.com).
See also this very complete answer, which summarizes this and other options for performing a lookup with multiple criteria.
PS1: Note that I used references to full columns, as per this.
PS2: This can be considered an enhancement to the solution by Sean for the case when the output column does not contain numbers.
References
[1] This post is written by JP Pinto, the winner of the Great White Shark Award given for the best article written about VLOOKUP during VLOOKUP Week.
Try this
=IF(A4=Data!$A$4:$A$741,IF(B4=Data!$B$4:$B$741,"Hai"))

Resources