Selecting from Many to many - excel

How can I in Excel, resolve this question about this table:
Invoice Number | Item | Product | Value
1001 | 1 | potatoes | 100
1001 | 2 | tomatoes | 150
1002 | 1 | potatoes | 100
1003 | 1 | water | 50
1004 | 1 | potatoes | 100
1004 | 2 | onions | 120
If I ask the questions:
Which an how many of these invoices have no potatoes or tomatoes ?
the answer should be, in this case: invoice 1003 / number = 1
How can I find it in Excel? Is there a formula for this question?

You can do it using the helper column. Place the following formula in it:
=IF(AND(COUNTIFS($A$2:$A$7,$A2,$C$2:$C$7,"potatoes")=0,COUNTIFS($A$2:$A$7,$A2,$C$2:$C$7,"onions")=0),IF(COUNTIFS($A$1:$A1,A2,$E$1:$E1,"Ok")=0,"Ok",""),"")
copy/paste the formula to the whole column, then you can use the count() function or filter by "Ok" values.

The feature you want to use is Pivot Tables. It's really easy to do exactly what you want with just a few clicks once you learn how to use that feature.

Related

Finding Max Values depending on Lookup Values

I have Sale Invoices for bread, jam, etc. like this table.
+-------+--------+-------+
| Item | Date | Price |
+-------+--------+-------+
| Bread | 1-Dec | 5 |
+-------+--------+-------+
| Jam | 1-Dec | 5 |
+-------+--------+-------+
| Bread | 8-Dec | 6 |
+-------+--------+-------+
| Jam | 8-Dec | 4 |
+-------+--------+-------+
| Bread | 15-Dec | 4 |
+-------+--------+-------+
| Jam | 15-Dec | 7 |
+-------+--------+-------+
I want the highest price date for each item like
+-------+--------+---------------+
| Item | Date | Highest Price |
+-------+--------+---------------+
| Bread | 8-Dec | 6 |
+-------+--------+---------------+
| Jam | 15-Dec | 7 |
+-------+--------+---------------+
It is like finding Max Values depending on Lookup Values. It is very much like Group By and Max in SQL. How do I do it in excel? I've tried index match and also googling. Nothing helps. Please help me.
This is typically done through a pivot table:
Select your data.
Insert a pivot table.
In your case use "Item" & "Date" as rows.
In your case use "Price" as value.
Then click "Price" and under it's field settings choose "Max".
Then in the pivot table itself right any date, click "Filter" > "Top Ten" and make that top 1 based on the max price.
There are many ways to do this through formulae, but if one has Excel O365 it can be done through one single formula, for example:
Formula in E2:
=TRANSPOSE(CHOOSE({1,2,3},TRANSPOSE(UNIQUE(A2:A7)),TRANSPOSE(MINIFS(B2:B7,A2:A7,UNIQUE(A2:A7),C2:C7,MAXIFS(C2:C7,A2:A7,UNIQUE(A2:A7)))),TRANSPOSE(MAXIFS(C2:C7,A2:A7,UNIQUE(A2:A7)))))
Or:
=FILTER(A2:C7,ISNUMBER(MATCH(A2:A7,UNIQUE(A2:A7),0))*LET(X,MAXIFS(C2:C7,A2:A7,UNIQUE(A2:A7)),ISNUMBER(MATCH(C2:C7,MAXIFS(C2:C7,A2:A7,UNIQUE(A2:A7))))*ISNUMBER(MATCH(B2:B7,MINIFS(B2:B7,A2:A7,UNIQUE(A2:A7),C2:C7,X),0))))

Using IF AND to calculate based on one or more criteria

Within a resource planner, my data has a row for each employee, and columns detailing the team they work for. Another column details the available days they will work in the year. The teams are also displayed along a row at the top, see below :
A | B | C | D | E | F | G |
1 Employee | Team 1 | Team 2 | Days | Finance | Risk | IT |
2 Employee 1 | Finance | | 170 | | | |
3 Employee 2 | Risk | Finance | 170 | | | |
4 Employee 3 | Finance | | 170 | | | |
5 Employee 4 | IT | Risk | 170 | | | |
6 Employee 5 | IT | Finance | 170 | | | |
I want to use columns E:G as a supply calculator per team. Therefore, the formula in cell E2 would be "=IF(B2=E1,D2,0)" and copied along the row, returning the 170 days under Finance and 0 under the rest.
The issue lies where an employee divides his time between two different teams. As you can see, some employees can work for 2 different teams (Employee 2 works for both Finance and Risk, for example). The formula in E3 would therefore need to be some kind of IF AND, where if a value is present in the Team 2 column (C), the value in the Days column (D) would be divided by two and split across the relevent team columns.
I've tried a few options, IF AND, nested IFS etc but cant seem to get the syntax correct. Any help greatly appreciated.
=IF(ISNUMBER(MATCH(E$1,$B2:$C2,0)),$D2/COUNTA($B2:$C2),0)
You actually want OR and COUNTA:
=IF(OR($B2=E$1,$C2=E$1),$D2/COUNTA($B2:$C2),0)

Excel: count items from A and sum up value from B if identical

I want to do something very similar to what's been asked and answered here, although I don't want to have duplicates: Find count of items in column and add the values from another column
Basically, I have a column A with duplicated names, and different values associated in column B. In column C I want the name and in column D the summed up value. The problem with SUMIF is that it will show me several time the name and the summed up values, while I want to see it only once.
To make it more clear, here's the result I'm looking for:
A | B | C | D
------------+----------+-----------+---------
Name | Value | Name | Sum
------------+----------+-----------+---------
Potatoes | 9 | Potatoes | 13
Tomatoes | 4 | Tomatoes | 11
Carrots | 1 | Carrots | 16
Potatoes | 4 | Eggs | 5
Eggs | 5 | |
Tomatoes | 7 | |

Count distinct occurrences and averages in a column based on identifiers in another column

In MS Excel, I want to count the number of distinct categories (ignoring a specific item) based on a different column. Also, I want to find the average and the max for the same selection. This is the data:
+--------+-----------+-------+
| Person | idea | score |
+--------+-----------+-------+
| George | vacuum | 9 |
| George | box | 6 |
| George | x | 1 |
| Joe | scoop | 4 |
| Joe | x | 1 |
| Joe | x | 1 |
| Joe | scoop | 4 |
| Joe | gear | 7 |
| Mike | harvester | 10 |
| Mike | gear | 7 |
| Mike | box | 6 |
+--------+-----------+-------+
The result should be the following:
+--------+----------------+------------+-----------+
| Person | distinct ideas | Avg. score | Max score |
+--------+----------------+------------+-----------+
| George | 2 | 5.3 | 9 |
| Joe | 2 | 3.4 | 7 |
| Mike | 3 | 7.7 | 10 |
+--------+----------------+------------+-----------+
Because Joe has two "scoop" and one "gear" idea, and I want to ignore the "x" items.
I reluctantly gave up and did it manually for each person, e.g., this is for the first person:
SUM(IF(FREQUENCY(MATCH(B2:B4,B2:B4,0),MATCH(B2:B4,B2:B4,0))>0,1))-IF(COUNTIF(B2:B4,"x")>0,1,0)
Doesn't Excel have functions to return a range instead of a value? If I could select the range based on the name of the person in the first columns, I could count distinct occurrences or find the average in another column.
Add a 4th column and label it Distinct Ideas
If your table starts in A1, then:
EDIT: Formula changed to exclude "x". Screen shot also changed
D2: =IF(TRIM($B2)="x",0,IF(SUMPRODUCT(($A$2:$A2=A2)*($B$2:$B2=B2))>1,0,1))
and fill down.
Then construct a Pivot table
Person to Row Labels
Distinct Ideas to Values area
score to Values and select to Average
Score to Values area and Select Max
Format as desired. Here is one result:

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