Google sheets, adding a value to a cell based on the contents of another - excel

This may be delving in to scripting territory rather than formula, but I was wondering if it's possible to use google sheets to add values to a cell based on the contents of another? For example, If I had a sheet arranged like the following:
Column A|Column B|Column C|Column D
Apples Oranges Grapes
Tomatoes Grapes Oranges
Melons Apples Tomatoes
Grapes Lemons Apples
And then I had another section that had
Column G|Column H
Apples 1
Tomates 2
Oranges 3
Grapes 4
Melons 5
Lemons 6
Is there a formula that will let me populate the contents of column D by reading columns A - C on each row and adding the values set on column H? Making Column D read something like 8, 9, 8 etc?
I hope this question makes sense, thanks and apologies for the shoddy formatting!

=SUMPRODUCT(IFERROR(VLOOKUP(A2:C2,G:H,2,0)))

For google-spreadsheets
Please try this single-formula solution:
=mmult(filter(VLOOKUP(A:C,G:H,2,0),A:A<>""),ArrayFormula(transpose(sign(column(A:C)))))
Paste it in D1.
Here's a sample file of sum with arrayFormula.

Related

How to retrieve Top 2 rows from each group in excel sheet?

The problem is simple to understand. I just need to know a formula that will help find a way to fetch the top 2 rows of each group in an excel sheet.
The below example is grouped by column 1.
Example
Given Table:
Column 1
Column 2
Apple
A102012
Apple
A102013
Apple
A102014
Banana
A102015
Banana
A102016
Banana
A102017
Coconut
A102017
Result:
Column 1
Column 2
Apple
A102012
Apple
A102013
Banana
A102015
Banana
A102016
Coconut
A102017
Try:
Formula in D1:
=REDUCE(A1:B1,UNIQUE(A2:A8),LAMBDA(a,b,VSTACK(a,TAKE(FILTER(A2:B8,A2:A8=b),2))))
To mimic this for Google Sheets:
=REDUCE(A1:B1,UNIQUE(A2:A8),LAMBDA(a,b,{a;QUERY(A2:B8,"Where A='"&b&"' limit 2")}))
A much slower alternative is:
=FILTER(A:B,INDEX(COUNTIFS(A:A,A:A,ROW(A:A),"<="&ROW(A:A)))<3)
A faster method than countifs not using most recent additions to Excel, if it can be assumed that data are pre-sorted:
=LET(count,COUNTA(A:A),Column1,A2:INDEX(A:A,count),Column12,A2:INDEX(B:B,count),FILTER(Column12,SCAN(0,SEQUENCE(count-1),LAMBDA(a,c,IF(c=1,1,IF(INDEX(Column1,c)=INDEX(Column1,c-1),a+1,1))))<=2))
or in Google Sheets:
=ArrayFormula(lambda(Column12,filter(Column12,SCAN(0,SEQUENCE(rows(Column12)),LAMBDA(a,c,IF(c=1,1,IF(INDEX(Column12,c,1)=INDEX(Column12,c-1,1),a+1,1))))<=2))(filter(A2:B,A2:A<>"")))
If you have Excel 365 you can also use this formula
=LET(rank,MAP(tblData[value],tblData[fruit],
LAMBDA(v,f,SUMPRODUCT((tblData[fruit]=f)*(v<tblData[value]))+1)),
FILTER(tblData,rank<=2))
The MAP function calculates the rank of each row within its group.
Then we can filter by that list.

How to populate columns with data in Excel using unique row combinations between two columns

This seems like it should be easy enough to do, but I can't seem to figure it out or find a tutorial.
I have two columns containing values. I would like the unique column combinations to repeat in another set of columns, and count the instances.
COLUMN A COLUMN B COLUMN C COLUMN D COLUMN E
John Apples John Apples 2
John Apples John Bananas 1
John Bananas Sara Apples 1
Sara Apples Sara Kiwi 1
Sara Kiwi Mike Carrots 2
Mike Carrots Mike Kiwi 1
Mike Carrots Apples 2
Mike Kiwi Carrots 1
Apples Kiwi 1
Apples
Carrots
Kiwi
I was able to transfer the unique values from one column to another using INDEX and MATCH, but can't get it to work with two columns.
This tutorial shows what I am looking for, but I'd like the second set of data to stay in a column, and not transpose into rows. https://www.extendoffice.com/documents/excel/3358-excel-transpose-unique-values.html
Try following this short animated screen capture finishing with the following formula in E2.
=COUNTIFS(A:A, IF(LEN(C2), C2, ""), B:B, D2)
What you describe is called a Pivot Table. Drag Name and Fruit into the rows area and Fruit again into the Values area to have it counted. Pivot tables can have different layouts, i.e. with repeating labels, or in compact format.

Excel COUNTIFS multiple and sequential criteria

Column A has: Apples Oranges Pears Bananas Mangos multiple times and in random orders.
Column C has: Red Orange Yellow Blue Purple corresponding to column A multiple times and in random orders.
I am looking for a formula which counts or sums all instances where Pears immediately follow Apples (i.e. the row below Apples) AND Pears are also Orange
I can return Apples and Pears and even Pears that are Orange but I cannot figure out how to return instances of Pears that are Orange which immediately follow Apples
Use COUNTIFS() with ranges of the same size that are offset:
=COUNTIFS(A$1:A$1040000,"Apples",A$2:A$1040001,"Pear",C$2:C$1040001,"Orange")

A Lookup of ALL values that match a Date

I'm trying to create a sheet that looks through 3 other sheets and combines only the data from all 3 that match today's date.
So if these are my sheets
Data 1:
x y
7/8/2016 Bananas
7/7/2016 Apples
Data 2
x y
7/8/2016 Oranges
7/7/2016 Grapes
Data 3
x y
7/8/2016 Pineapple
7/7/2016 Grapefruit
And I need a formula that returns the following result
x
Bananas
Oranges
Pineapple
Replace Bananas with
=INDEX('Data 1'!B:B,MATCH(Today(),'Data 1'!A:A,0))
Replace Oranges with
=INDEX('Data 2'!B:B,MATCH(Today(),'Data 2'!A:A,0))
and instead of Pineapple you should use
=INDEX('Data 3'!B:B,MATCH(Today(),'Data 3'!A:A,0))
All of the above assumes that the date is in column A of the sheets while the fruits are in column B.
Updated the functions with Today() thanks to #ForwardEd.

miss and match on excel

I'm not even sure if what i want to happen is possible but here it is :
So i have a list on column A and another on column B. Say, column A has apples, bananas, eggs... Then column B has apple pies, banana pies, egg pies...on column C, I want excel to tell me that apples and apple pies match and bananas and banana pies match, and so on. Then tell me if they don't match at all. I want it so that even if i want 2 values from column A to match with a value in column B. For example aside from apples there could also be pears in column A but i would still want pears to return a match value with apple pies. I hope this is not too confusing
... Thanks in advance!
Ok, I am going to give you multiple answers because I am not sure what the question is. If Gary's Student's comment is the right answer and you just want to match the contents then all you need to do is put this in C2 and copy it to every row:
=IF(ISERROR(FIND(A2,B2)),"no match","match")
But if your comment about 1-2=bad, 3-8=good and 9-10=very good is what you really want then all you need to do is put this in C2 and copy it to every row:
=IF(B2=CHOOSE(A2,"bad","bad","good","good","good","good","good","good","very good","very good"),"match","no match")
What that does is change the number in column A to be the equivalent string and then match that string against column B.
But if you are looking for a solution that works for both things then you need a dictionary. If you use ALL the piossible values from B as the keys and each matching value from A as the values then you can call MATCH twice and see if the value belongs to the key.
So for example the dictionary for the pie example might look like this (notice that pies can have more than one ingredient):
E F G H I J K
1 Key Value 1 Value 2 Value 3 Value 4 Value 5 Value 6
2 lemon pie lemon egg
3 apple pie apple pear
4 pear pie pear
5 egg pie egg
And the dictionary for the bad and good example would look like:
E F G H I J K
1 Key Value 1 Value 2 Value 3 Value 4 Value 5 Value 6
2 bad 1 2
3 good 3 4 5 6 7 8
4 very good 9 10
Then you can stick this in C2 and copy it to every row:
=IF(ISNA(MATCH(A2,OFFSET(F$1:O$1,MATCH(B2,E$2:E$20,0),0),0)),"no match","match")
What this does is look up the value in column B in the dictionary and find what row it is in. Then it offsets F$1:O$1 by that many rows so that the range for the outside match is the correct list of incgredients. Then it matches the value in column A by the list of ingredients that the offseted inside match produced.
Maybe some screenshots will help:

Resources