Indexing multiple columns in Excel, return neighboring column - excel

I am working on an excel sheet that will help me with meal-planning. Currently, I have my data stored in a manner like demonstrated below:
**Monday**
Breakfast Bagel 1 Cream Cheese 1
Lunch Spinach 1 Eggs 4 Cream Cheese 1
Dinner Pork 1 Eggs 2
**Tuesday**
Breakfast Cereal 2 Milk 1 Eggs 3
Lunch Bagel 1 Butter 1
Dinner Eggs 2
CURRENT OUTPUT:
Ingredients Needed:
Eggs 2
Bagel 2
Spinach 1
Pork 1
Cereal 2
Milk 0
Butter 0
Cream Cheese 0
Where the numbers represent the number of servings of each ingredient I need to buy.
The problem I am facing is that my current formula:
=INDEX($C$12:$C$58, SMALL(IF(ISNUMBER(SEARCH($B$60, $B$12:$B$58)), MATCH(ROW($B$12:$B$58), ROW($B$12:$B$58))), ROW(B1)))
Only indexes one row at a time. For example, if I am searching for how many Eggs I need to buy for the week, the formula would return 2 eggs (because it is only searching column B for Eggs and returning column C).
Is there a work-around that would allow me to be able to return the full number of ingredients I need to buy? I realize I could index each column individually, however, since I have many ingredients (100+), using my current formula doesn't seem feasible.
Any help is massively appreciated

You can use SUMIF, where the sum range is offset from the criteria range. For example, for simplicity, let's say that C12 to H19 contains the data (ingredient and quantity), try...
=SUMIF($C$12:$G$19,B60,$D$12:$H$19)
...where B60 contains the ingredient of interest. Notice that the sum range D12:H19 is offset from the criteria range C12:G19.

Related

Summarizing Excel with multiple columns

I have Excel data in a table with a single row, and multiple values in two categories, and I want to summarize the two categories.
Input data:
Recipe
Meal
Ingredients
Plum pie
Coffee
Dessert
Plums
Sugar
Eggs
Plum jam
Breakfast
Coffee
Plums
Sugar
Fried eggs
Breakfast
Lunch
Eggs
Pancakes
Breakfast
Dessert
Eggs
Flour
Milk
Desired output:
Eggs
Flour
Milk
Plums
Sugar
Breakfast
2
1
1
1
1
Coffee
1
2
2
Lunch
1
Dessert
1
1
1
Of course restructuring the input data and summarizing via a Pivot table or Countif is a solution, but not a practical possibility due to the source of the data.
Can anybody help with an intelligent solution (and apologies for the table pictures - can anybody help pasting tables other than as pictures - I solved the tables problem partially via https://tableconvert.com/excel-to-markdown but alas - no colors)
Thanks,
Anders
Quite verbose and an high percentage of lambda, but dynamic enough for you to only enter two variables at the start:
Formula in I2
=LET(meals,B2:C5,ingredients,D2:F5,uq_ing,SORT(UNIQUE(TOROW(ingredients,1),1),,,1),REDUCE(HSTACK("",uq_ing),SORT(UNIQUE(TOCOL(meals,1))),LAMBDA(x,y,VSTACK(x,HSTACK(y,MAP(uq_ing,LAMBDA(z,SUM(BYROW(meals,LAMBDA(v,SUM(N(v=y))))*BYROW(ingredients,LAMBDA(w,SUM(N(w=z))))))))))))
=LET(
meal, B2:C5,
ing, D2:F5,
uMeal, UNIQUE(TOCOL(meal)),
uIng, UNIQUE(TOCOL(ing, 1)),
arr, MAKEARRAY(
ROWS(uMeal),
ROWS(uIng),
LAMBDA(row, col,
SUM(
BYROW(meal, LAMBDA(r, SUM(--(r = INDEX(uMeal, row))))) *
BYROW(ing, LAMBDA(r, SUM(--(r = INDEX(uIng, col)))))
)
)
),
VSTACK(HSTACK("", TRANSPOSE(uIng)), HSTACK(uMeal, arr))
)
Probably very similar to #JvdV's answer, but at least you can check the results against each other.

Count apple based on common ID between two tables

I have two Excel tables that look like this:
Table 1
A B C
ID Stocked Sale
1 shelf sold
5 display sold
9 shelf sold
12 shelf sold
13 shelf
Table 2
P Q
ID Stocked
a2 apple
88
83
1 apple
9 apple
I need to count the total number of apples by common ID, given that apples are:
stocked on the shelf in Table 1
sold in Table 1
So, the outcome has to be 2 apples.
Here is what I have tried thus far:
COUNTIFS(B:B, "shelf", C:C, "sold", Q:Q, "apple")
I can't figure out how to count by common id...
Something like this should work for you:
=SUMPRODUCT(COUNTIFS(A:A,REPT($P$2:$P$6,$Q$2:$Q$6="apple"),B:B,"shelf",C:C,"sold"))

Grand Total Issue in Cross Table of Spotfire

When I use FIRST(CG1) in 'Cell Values' the grand total is not summing up instead its showing one of the values from the result of FIRST(CG1).
Please advise if we have to always use sum(XXX) to get the grand total summed up.
Short answer, yes if you want the Grand Total to be a summation of your data. Applying a grand total to a different aggregation will have different results.
AVG will average the averages of your Category Axis
MAX will take the MAX of the Max for each category
Cumulative Sum will take the "Last" value in your Category since it doesn't have any additional values to SUM up.
Product will take the Product of Products
First and Last you are already aware of.
Long Answer:
You actually CAN sum the first value of a column from a column grouping.
For example, consider the following data set.
[Grouping] [Food] [Color] [Weight]
Fruit Apple Yellow 4
Fruit Apple Green 2
Fruit Apple Red 4
Fruit Banana Yellow 5
Fruit Banana Brown 2
Fruit Orange Orange 3
Vegetable Carrot Orange 4
If, in your custom expression, you put
Sum(if(RankReal([Grouping], "ties.method=first", [Food]) = 1, [Weight], 0))
it will find the first instance of each food in your data set, so regardless of how you group the left, your results, subtotals, and grand totals will sum only the first instance of each food.
So you will be able to see the following:
Fruit Apple 4
Banana 5
Orange 3
Subtotal: 12
Vegetable Carrot 4
Subtotal: 4
Grand Total: 16

comparing two columns in excel (VLOOKUP not working)

I have been breaking my head with this problem since morning and I haven't found a solution. Please give your valuable pointers if possible, so that I can try to find the solution.
I basically have two sets of data- an old list and a new list. I wish to compare the new list( comparing name and country together) with an old list, since the new list has a few additional entries. Later on, I would like to create a new list with common entries from both old and new list and add all the new entries below the common ones ( if possible, else I will do that manually later on but I would like Excel to tell me that this is a new entry). Sorry, if this has not been well explained, but maybe the following illustration helps
Old List
Item No. Name Country
1 Apples Italy
3 Banana Spain
4 Grapes Slovakia
5 Pineapple Greece
8 Banana Czech Republic
14 Apples India
23 Pineapple Hungary
19 Peach USA
2 Strawberries France
New List
Item No. Name Country
4 Grapes Slovakia
Mango Pakistan
14 Apples India
Oranges Mexico
19 Peach USA
2 Strawberries France
1 Apples Italy
3 Banana Spain
23 Pineapple Hungary
Avocado Netherlands
Expected Output:
List with common serial No.s based on common names from both lists
Item No.Name Country
4 Grapes Slovakia
14 Apples India
19 Peach USA
2 Strawberries France
1 Apples Italy
3 Banana Spain
23 Pineapple Hungary
Mango Pakistan
Oranges Mexico
Avocado Netherlands
As can be seen in this attachment, I have an old list with Item No., Name and Country. Let's assume that the item numbers have been classified based on some code words. In the second list, there are again Item No.s, Name and Country but some item numbers haven't been filled ( since they are new and have not yet been sorted). Now, I want Excel to compare the names AND countries of both data and provide the common Item No. output if there is a match. If there is no match, then I would like Excel to tell me that this is a new entry. I looked up on various forums and I realized that VLOOKUP command only allows me to search on Name OR Country would give me the common entries of Names/Countries respectively but not Item No.s. Is there any formula that could help me solve this problem?
Just paste the list together, then sort it, and then remove the duplicates. Removing duplicates is built-in into Excel starting from version 2007, you will find it in the Data ribbon (see http://office.microsoft.com/en-001/excel-help/filter-for-unique-values-or-remove-duplicate-values-HP010073943.aspx).
To use VLOOKUP just concatenate Name and Country, for example, B2 & "-" & C2. You can then do a lookup on the concatenated values in your source table:
VLOOKUP(B2 & "-" & C2,NewList!D2:E100,2,False)
This assumes that the concatenated column is in D in your new table, and that you've copied the numbers to column E (VLOOKUP can't look to the right). I put in the dash for readablility and to avoid the chance that a Country ends with a number, unlikely as that might be.

Calculated column to show number of items selected in a multichoice field

In SharePoint I have a table with a lookup column that takes in multiple values. I am having a problem finding a code for a calculated column that counts how many values the user chose. For example,
Favorite Ice Cream
1 Vanilla; Chocolate; Strawberry
2 Cookies and Cream; Mint
3 Coconut; Chocolate; Butter Pecan; Strawberry
And an adjacent column will be...
Number of total Ice Cream
1 3
2 2
3 4
Thank you in advance!

Resources