Sum/Multiply every value near the same name - excel

I'm trying to find a formula that can help me in a problem.
This formula should SUM (or work) with every cell that is near (always on the left) a cell that has the same name. Like below:
Consider every capital letter as a "recipe" and every lowercase letter as an "ingredient". To the left of every ingredient there's a number that indicates the amount of ingredient needed in that recipe.
At the left of the table there's the list of the ingredients.
Using COUNTIF i can know how many recipes have the same ingredients, but i'm searching something to sum (or multiply, it's the same once i understood the process) every left value of the same ingredient.
As you can see i can't use SUMIF (or SUM(FILTER()) ) since for example the element "b" can be found on the 3rd and 5th column and they're not on the same column.
I tried to use INDEX() and MATCH(), and could've used also LOOKUP(),VLOOKUP(),HLOOKUP(), but as you can see there are multiple instances of the same element, and the formula returns me only the same value (Also using ROW()-1 doesn't work for the multiple elements).
Now with this little table i can calculate the numbers easily (e.g. i know that element "a" is needed 2+3+2=7 times) but since the real table has 600+ elements between "recipes" and "ingredients" I wondered if there was a way to do this.
I'm working on OpenOffice but I have no problem on using Excel.
Thank you for your answers.

Are you looking for something like this?:-
=SUM(IF(ISNUMBER($B$2:$F$7),$B$2:$F$7)*($C$2:$G$7=I7))
Must be entered as an array formula using CtrlShiftEnter

Related

Excel formula to get unique value from a lookup only if all values match

I'm trying to find a way to perform an INDEX MATCH lookup that goes beyond the first match to check if all matching values are equivalent. I've found formulas that will return all matches, but what I'd like to do is have the matching value returned in the formula cell, but only if all values returned are the same.
Here's an example:
I'm matching the report number with the report number below and only picking up the area value if all report-area combinations are the same. Is there a clean way to do this?
Dan.
My solution may seem a bit messy, but you can make it simpler as you go, once you start implementing it:
First, I made a Report Count. (How many 12345 Reports are there in total, and so on).
=COUNTIF($A$2:$A$10;A2)
Then, I concat the Report-Area to get a unique identifier for every Report-Area combination.
=A2&"-"&B2
Now, I make a Count of that column, meaning I count how many combinations are there for each case (e.g. how many 12345-2C are there in total).
=COUNTIF($D$2:$D$10;D2)
Then, I create an "Ok" Column for checking if the Report Count matches the Concat Count.
=IF(C2=E2;"OK";"")
That said, we have our table ready for checking what you're looking for.
In just one formula (the one under Lookup header) on cell B13:
=IF(INDEX(F2:F10;MATCH(A13;A2:A10;0))="OK";INDEX(B2:B10;MATCH(A13;A2:A10;0));"")
I check IF there's an "OK" on the OK column for that Report number.
If there is, I Search for the "Area" value for that Report number.
If there isn't an "OK", I leave a blank cell. (In your example, it's #N/A)
The formulas on H2, I2 and C13 are just for reference. Plain text.
Again, I know it seems messy, but if you're not too familiar with some Excel formulas and functions, this is a good way to learn and build complex formulas step by step (Just as our fellow n8 said)
I assume you understand how INDEX MATCH works. If you don't, I'll edit an explanation for you.
Good Luck!

How to use AverageIf worksheet function for calculating average date differences (in case date is filled in)

I'm making a summary of a list of tasks, and the corresponding dates (start date, first answer date, ...).
It looks more or less like the following:
Title Start date First answer
Task1 29/06/2018 02/07/2018
Task2 09/05/2018
Task3 13/06/2018 14/06/2018
I would like to calculate the average time, needed for the first answer to be given. In case no first answer is given yet, this entry needs to be ignored in the calculation of the average.
In order to be able to understand the formulas better, I've decided to use names for the headers, like:
Name "Header_Title" has value "Title"
Name "Header_Start_Date" has value "Start Date"
Name "Header_First_Answer" has value "First answer"
Also, the number of entries, defined as COUNTA(OFFSET(Header_Title;1;0):A1048576) has a name: Total_Count.
Next to that, I've created names for the ranges of the column values:
"All_Start_Dates" is defined as =OFFSET(Header_Start_Date;1;0):OFFSET(Header_Start_Date;Total_Count;0)
"All_First_Answered" is defined as =OFFSET(Header_First_Answer;1;0):OFFSET(Header_First_Answer;Total_Count;0)
Explanation : take the first entry under the header (column title) and go to the row, corresponding to the last task.
This makes it very easy to write a formula for calculating the average difference between those date columns:
{=AVERAGE(All_First_Answered_Dates-All_Start_Dates)}
// mind the {} for showing this is an array formula
Now the problem is: how to use the AverageIf worksheet function in order not to take into account the cases where First answer is not filled in?
I already tried using ">0" and ">"&0, but this does not work, the formulas are said not to be valid:
{=AVERAGEIF(All_First_Answered_Dates-All_Start_Dates;">0")}
{=AVERAGEIF(All_First_Answered_Dates-All_Start_Dates;">"&0)}
Does anybody have an idea?
Thanks in advance
P.s.1. As you can see, I'm using cell range A1048576 as the last entry of column A, does anybody know a more elegant way to describe this?
P.s.2. One extra thing, which would make my life easier, is the possibility to see which cells have a name (I was thinking about conditional formatting, but I didn't find the way to do this). Does anybody know if there is a way to highlight individual cells, linked to a name?
So my suggested answer would be
=AVERAGEIF(All_First_Answered,">0")-AVERAGEIF(All_First_Answered,">0",All_Start_Dates)
I'm assuming here that all start dates are present but first answered dates may be missing: you could easily add an extra condition for start date if you used AVERAGEIFS. Both parts of the formula include the same conditions so they are working on the same rows.
The intermediate columns above are just included by way of explanation.
Try an array formula.
If you're not familiar with array formulas, the significant difference is you press and hold Ctrl+Shift then hit Enter instead of just pressing Enter. You will see the formula preceded and followed by curly brackets. Do not type those. Those will appear automatically.
=AVERAGE(IF(INDIRECT("C14:C"&LOOKUP(2,1/(A:A<>""),ROW(A:A)))=0,"",INDIRECT("C14:C"&LOOKUP(2,1/(A:A<>""),ROW(A:A)))-INDIRECT("B14:B"&LOOKUP(2,1/(A:A<>""),ROW(A:A)))))

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..

How to get the unique value from a cell which repeats multiple times in excel?

Hi All i have a data of around 50000 candidates and one of the column contains the subject like below .
I want a formula in Column B to get the Unique Value from column A.
If all the values in "," are same then i need the Single value else all the cell Data.(There may be multiple comma separated entries)
I tried find formula but is not working.
Thanks in Advance.
This will work for any number of comma-separated entries:
=IF(REPT(LEFT(A2,FIND(",",A2&",")),1+LEN(A2)-LEN(SUBSTITUTE(A2,",","")))=A2&",",LEFT(A2,FIND(",",A2)-1),A2)
Regards
Bit of a mess but this will work:
=IF(ISNUMBER(SEARCH(MID($A2,1,SEARCH(",",$A2,1)-1),$A2,LEN(MID($A2,1,SEARCH(",",$A2,1)-1)))),IF(ISNUMBER(SEARCH(MID($A2,1,SEARCH(",",$A2,1)-1),$A2,LEN(MID($A2,1,SEARCH(",",$A2,1)-1))*2)),MID($A2,1,SEARCH(",",$A2,1)-1),$A2),$A2)
If search finds the first word again past the length of it it checks again past double it's length. If that's a match it returns just that word and otherwise returns the entire cell.
I will keep trying to find a more elegant solution but for now, this'll do. Well providing you are always searching on an index of 3. If you aren't I can still do it but would like to use helper columns (or have a crack at VBA which is easily up to the task, I wan't to see effort first though as I won't code for free as a rule of thumb)

How to sumif the vlookup value of a range?

I'm not sure how to explain what I am trying to achieve so I will start with the data I am working with:
1) A table that lists IDs corresponding to Games. Each game has several IDs.
2) A table that lists IDs and $ Earned on those IDs.
In another table, I have the list of games and want to return the sum of $ Earned on those games:
Tables 1,2,3
I was trying to do this with a combination of a SUMIF and VLOOKUP formula but I can't seem to find a way to do that because the VLOOKUP returns a value rather than a range. What I want to do is sum a sum_range ($ earned) if the lookup value of the range (game corresponding to the code) is a match.
I could simply add a column to the second table that returns the game of that code with a VLOOKUP. But the problem is that this would need to be done in a very large number of sheets, and with each time the new data is received.
Hopefully that made sense and thank you in advance for any help I can get!
Cheers,
Maria
Well this may be a bit of a cheat. if you look at your game code, you are either looking for basketball or baseball. So we could do a sum if the code contains one of those words.
If case sensitivity is important
=SUMPRODUCT(--(ISNUMBER(FIND("Basketball",B2:B16)))*C2:C16)
or if case sensitivity is not important
=SUMPRODUCT(--(ISNUMBER(SEARCH("Basketball",B2:B16)))*C2:C16)
B2:B16 would be your code in table 2
C2:C16 would be your $ earned column in C2
The formula would be placed where the ? cell is beside big win Basketball.
updated option for keyword
So if you are not looking for just baseball or basketball, but the entire string of the key words that you are looking for the total for, you could use the following provided the words in table three form part of the code when the spaces are removed.
=SUMPRODUCT(--(ISNUMBER(FIND(SUBSTITUTE(B19," ",""),B2:B16)))*C2:C16)
or
=SUMPRODUCT(--(ISNUMBER(SEARCH(SUBSTITUTE(B19," ",""),B2:B16)))*C2:C16)
This assumes the keyword your are looking for in the code is in B19. The substitute function removes the spaces to match your code.
In the second table add a (hidden) column, where you perform a VLOOKUP in the first table of the Code, retrieving the Game name.
Now you have something to base your SUMIF on: the value in the additional, hidden column should match the Game you have in your summary.

Resources