Sum by Dynamic Criteria List - excel

I am trying to use the function "SUMIFS" with "dynamic criteria".
See tables below.
In Table Overview Cell B2 I got the formula I try to figure out:
SUMIFS all Fruits (Table Criteria, Column A:A) in Table Data.
And if there is a new product, e.g. apple, I would like to add it in the Table Criteria in A4 as "apple", and my Overview should add the amount of the apples to fruits.
Any ideas?
Table "Overview"
|_| A | B |
|1| **Subject** **Count**
|2| Fruits 10
|3| Vegtables 20
|4|
Table "Criteria"
|_| A | B |
|1| **Fruits** **Vegtables**
|2| Banana Carrot
|3| Kiwi Broccoli
|4|
Table "Data"
|_| A | B |
|1| **Product** **Count**
|2| Banana 2
|3| Kiwi 3
|4| Banana 5
|5| Carrot 5
|6| Broccoli 15

Use:
=SUMPRODUCT(SUMIFS(B:B,A:A,INDEX($D$2:$E$2:INDEX(D:E,MATCH("zzz",INDEX(D:E,0,MATCH(G2,$D$1:$E$1,0))),MATCH(G2,$D$1:$E$1,0)),0,MATCH(G2,$D$1:$E$1,0))))
This is dynamic and will allow the addition of items to both input lists without the need to change the formula and still maintain the fewest iterations. The SUMPRODUCT forces the SUMIFS criteria to iterate and while we can put the full column in it will iterate 1.04 million times and that would slow down the calc.
Now if they are true structured tables in Excel then it can be simplified because the table would limit the iterations:
=SUMPRODUCT(SUMIFS(Data[Count],Data[Product],INDEX(Criteria,0,MATCH([#Subject],Criteria[#Headers],0))))

Related

Formula to find item from a list that has total price then cross reference the different lists that contain that item to find the value of item?

row example-
lets say in column one I have apple|banana|pear
column 2 is number of items in column 1 (3)
column 3 is total price of all 3 items (42)
so I know apple+banana+pear=42
Now throughout column 1 I have a bunch of variations of items with varrying amounts of 1-6 items(4 items apple|banana|pear|egg, etc.)
I could go through and filter the column for lists that contain lets say apples and find each price manually but I'm wondering if there is a formula that could complete this task automatically.
So in column 6-11 I would split the items so each has its own cell then in 12-17 I would run the formula to find the price of each item.
So for example it would look like
| 1 |2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| apple|banana|pear | 3| 42 |apple | banana | pear | 14 | 16 | 12|
So far all I have done is split each list into their own cells, and wrote a formula to figure out how many items in each list. I don't really know how to figure this out without AI or if its even possible on excel. I guess maybe vlookup a value and divide total by number of containers then average because I have about 1000 rows of lists so maybe it will give me the best estimate?

How to do VLOOKUP with a list of values

I have two sheet in excel.
In sheet2 I have a table with these fields:
NAME, SURNAME, CITY, AGE
In sheet1 I have to set field CITY and I want that table under this field will be with all the rows from sheet2 with selected CITY.
If I do a VLOOKUP I obioubsly get only first row of table.
Example:
A | B | C | D
NAME | SURNAME | CITY | AGE
Alex | Green | Rome | 18
Max | Brown | Rome | 21
Mary | White | Milan | 33
George | Violet | Rome | 27
In sheet 1 I have
A | B | C | D
CITY | Rome
NAME | SURNAME | CITY | AGE
VLOOKUP| VLOOKUP | VLOOKUP | VLOOKUP
VLOOKUP| VLOOKUP | VLOOKUP | VLOOKUP
VLOOKUP = VLOOKUP($B$2;Sheet2!A:D;1;0) -->
I wanted ALEX, MAX, GEORGE; I have ALEX, ALEX, ALEX
How can I do this without macros?
Thank you
For a simple data configuration like your sample pu this in Sheet1!A3 and fill both right and down,
=INDEX(Sheet2!A:A,AGGREGATE(15,6,ROW($2:$9)/(Sheet2!$C$2:$C$9=$B$1),ROW(1:1)))
For more complicated data configurations and retrievals put this in Sheet1!A3 and fill right and down,
=INDEX(Sheet2!$A:$D, AGGREGATE(15, 7, ROW($2:$9)/(Sheet2!$C$2:$C$9=$B$1), ROW(1:1)), MATCH(A$2, Sheet2!$1:$1, 0))
Use an IFERROR function 'wrapper' to avoid displaying worksheet errors when you run out of data to retrieve.

How to Assign row numbers based on row values - Excel

In the bellow excel data sheet, the values in the third column are manually entered. I would need a formula to automate this.
TYPE | CATEGORY | Expected_Value
fruits | apple | 1
fruits | apple | 2
fruits | apple | 3
fruits | bananna | 1
fruits | bananna | 2
fruits | mango | 1
fruits | mango | 2
fruits | mango | 3
fruits | mango | 4
fruits | mango | 5
Expected_Value represents the n-th duplicate of a given (TYPE, CATEGORY) couple.
Could someone help?
You need to use COUNTIF with an absolute reference and a relative reference. If your Category column spanned from B2 to B12 you could use this:
=COUNTIF($B$2:B2,B2)

List items from another list that have a value against them

I have 3 columns, the first column has data in it, against which the second one has some data.
Now I need to get a list of all the items in the first column in the third column.
The sheet as as below
Name | QTY | ACTIVE
----------------------
Apple | |
----------------------
Oranges | 10 |
----------------------
Pears | 5 |
----------------------
Plums | |
It needs to look like this
Name | QTY | ACTIVE
----------------------
Apple | | Oranges
----------------------
Oranges | 10 | Pears
----------------------
Pears | 5 |
----------------------
Plums | |
How can I do this either using a formula or a script.
What i've put above is just an example, its actually a long list of items against which there may or may not be quantities, therefore I only need a list of the items with quantities against them.
Thanks in advance.
if your using google sheets then you can use a filter function. Enter the formula and all the results will be listed in the cells below. Only items from column A that have data in Column B will be displayed.
=filter(A2:A,NOT(ISBLANK(B2:B)))
How it works
=filter(range,criteria)
You can also pull both the Name and Quantity by widening your range to include column B
=filter(A2:B,NOT(ISBLANK(B2:B)))
Note: If you get a #REF! error then you may not have left enough blank cells below your filter cell for the results to be displayed.
https://support.google.com/docs/answer/3093197?hl=en

Is it possible to populate sumif with dynamic range

I have the following data in Excel Worksheet A, which is a basic ledger of expenses:
The initial data looks like:
Week | Amount | Payee | Category
1 | 10.00 | John | Cookies
1 | 12.00 | Bill | Cookies
3 | 7.08 | Jason | Oranges
...
And I have assigned categories and calculate subtotals like this on another sheet using SUMIF :
Category | Total | Include?
Cookies | 22.00 | True
Oranges | 14.87 |
...
I'm trying to get to a report that sums if that Include? boolean is set. By using SUMIF again, I can summarize by week:
Total IncludeSet?
1 100.06
2 100.3 22.00
3 80.07
4 77.29
...
I know I could create an Extra column, and I could also try a SUMIFS and apply multiple criteria, but I'm up for learning how the pros would tackle this. At some point, I should just put this into MATLAB or a database.

Resources