I have an Excel table with states, names, and counts. I am trying to find the top name by sum of the count for each state. So, for example, with the following:
State | Name | Count
IA | Joe | 10
IA | John | 10
IA | Joe | 5
NE | Joe | 5
NE | John | 10
NE | John | 15
NE | Joe | 10
NE | Amy | 30
OH | Joe | 10
OH | John | 10
OH | Amy | 5
OH | Joe | 5
The expected results would be:
IA | Joe (15)
NE | Amy (30)
OH | Joe (15)
Any ideas on how to do this? Maybe something with pivot tables?
Couple of approaches stand out
1) use 2 pivots one that has row labels of name and states as column labels and sums the values. Second pivot is based on first pivot uses lists names as row labels and max of state as values, then use conditional formatting to high light those with the same grand total.
2nd option is similar to first but instead of using second pivot have seperate values for each state that have the formula (=max) of the state in the pivot then base the conditional formatting on that.
3rd option would be define it as a table and then use embedded SQL with the form to write a query to give you the sum and max by state Don't have an example of that one yet.
Related
I've spent pretty much all day trying to figure this out. I've read so many threads on here and on various other sites. This is what I'm trying to do:
I've got the total sales output. It's large and the number of items on it varies depending on the time frame it's looked at. There is a major lack in the system where I cannot get the figures by region. That information is not stored in the system. The records only store the customer's name, the product information, number of units, price, and purchase date. I want to get the total number of each item sold by region so that I can compare item popularity across regions.
There are only about 50 customers, so it is feasible for me to create a separate sheet assigning a region to the customers.
So, I have three sheets:
Sheet 1: Sales
+-----------------------------------------------------+
|Customer Name | Product | Amount | Price | Date |
-------------------------------------------------------
| Joe's Fish | RT-01 | 7 | 5.45 | 2020/5/20 |
-------------------------------------------------------
| Joe's Fish | CB-23 | 17 | 0.55 | 2020/5/20 |
-------------------------------------------------------
| Mack's Bugs | RT-01 | 4 | 4.45 | 2020/4/20 |
-------------------------------------------------------
| Joe's Fish | VX-28 | 1 | 1.20 | 2020/5/13 |
-------------------------------------------------------
| Karen's \/ | RT-01 | 9 | 3.45 | 2020/3/20 |
+-----------------------------------------------------+
Sheet 2: Regions
+----------------------+
| Customer | Region |
------------------------
| Joe's Fish | NA |
------------------------
| Mack's Bugs | NA |
------------------------
| Karen's \/ | EU |
+----------------------+
And my results are going in Sheet 3:
+----------------------+
| | NA | EU |
------------------------
| RT-01 | 11 | 9 |
+----------------------+
So looking at the data I made up for this question, I want to compare the number of RW-01's sold in North America to those sold in Europe. I can do it if I add an INDEX MATCH column to the end of the sales sheet, but I would have to do that every time I update the sales information.
Is there some way to do a SUMIFS like:
SUMIFS(Sheet1!$D:$D,Sheet1!$A:$A,INDEX(Sheet2!$B:$B,MATCH(Sheet1!#Current A#,Sheet2!$A:$A))=Sheet3!$B2,Sheet1!$B:$B,Sheet3!$A3)
?
I think it's difficult to do it with a SUMIFS because the columns you're matching have to be ranges, but you can certainly do it with a SUMPRODUCT and COUNTIFS:
=SUMPRODUCT(Sheet1!$C$2:$C$10*(Sheet1!$B$2:$B$10=$A2)*COUNTIFS(Sheet2!$A$2:$A$5,Sheet1!$A$2:$A$10,Sheet2!$B$2:$B$5,B$1))
I don't recommend using full-column references because it could be slow.
BTW I was assuming that there were no duplicates in Sheet2 for a particular combination of customer and region - if there were, you could use
=SUMPRODUCT(Sheet1!$C$2:$C$10*(Sheet1!$B$2:$B$10=$A2)*
(COUNTIFS(Sheet2!$A$2:$A$5,Sheet1!$A$2:$A$10,Sheet2!$B$2:$B$5,B$1)>0))
EDIT
It is worth using a dynamic version of the formula, though it is not elegant:
=SUM(Sheet1!$C2:INDEX(Sheet1!$C:$C,MATCH(2,1/(Sheet1!$C:$C<>"")))*(Sheet1!$B2:INDEX(Sheet1!$B:$B,MATCH(2,1/(Sheet1!$B:$B<>"")))=$A2)*
(COUNTIFS(Sheet2!$A$2:INDEX(Sheet2!$A:$A,MATCH(2,1/(Sheet2!$A:$A<>""))),Sheet1!$A2:INDEX(Sheet1!$A:$A,MATCH(2,1/(Sheet1!$A:$A<>""))),Sheet2!$B$2:INDEX(Sheet2!$B:$B,MATCH(2,1/(Sheet2!$B:$B<>""))),B$1)>0))
As you would need to make the match in memory I don't think it's feasible in Excel, you'll have to use a vba dictionary.
On the other hand, if the number of columns is fixed in your sales sheet, you can just format as table and add your index match in F.
When updating the sales data delete all lines as of line 3 and copy paste the update value. Excel will automatically apply the index match on all rows.
I have an excel sheet (called Sheet1) with rows of data that look like this:
Unit | Names | Begin_Date | End_Date
-----------------------------------
A | Jones | 1/1/2016 | 1/4/2018
A | Frank | 2/11/2018 |
B | Adam | 3/5/2011 |
C | Jane | 6/9/2012 | 7/14/2016
C | John | 7/28/2016 | 9/22/2017
C | Joe | 12/31/2017 | 1/1/2019
C | Joe | 1/2/2019 |
I am trying to get it into a format that has the units as column headers and dates as rows. The idea is that for every day between the begin and end dates, the name of the person should be in the appropriate cell. If there is a gap between the end date of one person and the begin date of the next within the same unit, the formula will list "vacant". It is assumed each unit was vacant before the first "begin date" for that unit, and blanks for end dates mean that the person still occupies that unit. Ideally the completed data set would look like this, on Sheet2:
Date | A | B | C |
-------------------------------------
3/5/2011 | Vacant | Adam | Vacant
3/6/2011 | Vacant | Adam | Vacant
...
6/9/2012 | Vacant | Adam | Jane
...
1/1/2016 | Jones | Adam | Jane
...
7/14/2016 | Jones | Adam | Jane
7/15/2016 | Jones | Adam | Vacant
7/16/2016 | Jones | Adam | Vacant
...
7/28/2016 | Jones | Adam | John
...
1/4/2018 | Jones | Adam | Joe
1/5/2018 | Vacant | Adam | Joe
etc.
The formula I have thus far populates the first values, i.e. the first person to live in the unit or, if no one, then it lists "vacant" on Sheet2. However, I am not sure how to extend it to look for the next person. I've listed all the dates in column A and all of the unique Unit names in row 1. Any help or advice would be appreciated!
=iferror(if(index(Sheet1!Names,match(1,(Sheet2!A$2=Sheet1!Begin_Date)*(Sheet2!$A3=Sheet1!End_Date),0))=Index(Sheet1!Names,match($A2,ArrayFormula(min(Sheet1!Unit=B$2,Sheet1!Begin_Date)),"Vacant",Index(Sheet1!Names,match($A2,ArrayFormula(min(Sheet1!Unit=B$2,Sheet1!Begin_Date))),Index(Sheet1!Names,match($A2,ArrayFormula(min(Sheet1!Unit=B$2,Sheet1!Begin_Date)))
This uses aggregate and is basically an array formula but without having to be entered with
CtrlShiftEnter
=IF($F2="","",IFERROR(INDEX($B:$B,AGGREGATE(15,6,ROW($A$2:$A$10)/
(($A$2:$A$10=G$1)*($F2>=$C$2:$C$10)*(($F2<=$D$2:$D$10)+($D$2:$D$10=""))),1)),"Vacant"))
Aggregate(15,6...1) woks out the minimum value of the array inside it, ignoring any error values. This array consists of the rows 2-10 divided by the conditions on the rows. The conditions are set up (as you did) using * for AND and + for OR. Where the conditions are false, this leads to a division by zero which gives an error, so only the rows which satisfy the condition are taken into account.
You can also use this
=IF($F2="","",IFERROR(INDEX($B$2:$B$10,MATCH(1,
($A$2:$A$10=G$1)*($F2>=$C$2:$C$10)*(($F2<=$D$2:$D$10)+($D$2:$D$10="")),0)),"Vacant"))
entered as an array formula.
I have a table of expenses with the supplier and the amount like:
supplier | amount
=====================
Jon | 13
Jon | 12
Jane | 3
Jack | 15
Jon | 2
Jack | 8
Now I like to know how much I spent for each supplier. The result should be
supplier | total
=====================
Jon | 27
Jane | 3
Jack | 23
The second table should get created dynamically so if I add "Jenny" to the first list it will show up as well.
Create a pivot table, reference your data table as the data source and place suppliers as row and amount as values. Make sure your settings for the value field is set to sum.
Then make sure your pivot setting is set to update whenever the datatable changes.
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.
I feel a bit embarrassed for asking this but here goes:
I'm using Excel 2010 and I have a worksheet containing 700+ customer satisfaction survey responses. Each row is a survey with a 1-5 or NA response to 5 questions. It looks like the following:
+-Agent--+--Q1--+--Q2--+--Q3--+
| | | | |
| Jeff | 5 | 5 | 5 |
+--------+------+------+------+
| James | 1 | 1 | 1 |
+--------+------+------+------+
| Jack | 5 | 5 | 5 |
+--------+------+------+------+
| Jeff | 3 | NA | 5 |
+--------+------+------+------+
| Jeff | NA | NA | 3 |
+--------+------+------+------+
| James | 5 | 5 | 5 |
+--------+------+------+------+
| ... | ... | ... | ... |
+--------+------+------+------+
I want to create a worksheet listing each agent in column A and the average of all of questions answered regarding them. I tried a formula like AVERAGEIF(SurveyResponses!A2:A7,A2,SurveyResponses!B2:D7) where A2 contains the agent's name, but it doesn't appear to work properly.
For example, I get a 5.00 average for some agents when it should be a 4.61. When I look in the Function Arguments screen for my AVERAGEIF on this person, it looks like it recognizes the values properly. The Average_rage shows {"NA","NA","NA","NA",1;5,5,5,5,5;5,... but the returned value below that says = 5 which is not right since there is a 1.
Can anyone guide me in the right direction?
AVERAGEIF works like SUMIF, the second range used is actually the same size and shape as the first range, starting with the top left cell, so when you use this
=AVERAGEIF(SurveyResponses!A2:A7,A2,SurveyResponses!B2:D7)
because the first range is a single column then the second range used must be too (there's a 1 to 1 relationship between the cells) so because the top left cell in SurveyResponses!B2:D7 is SurveyResponses!B2 the range begins there and is the same size and shape as SurveyResponses!A2:A7
....so you are actually getting this....
=AVERAGEIF(SurveyResponses!A2:A7,A2,SurveyResponses!B2:B7)
AVERAGEIF help does tell you that but it isn't very clear
If you want the ranges to be different sizes you need an "array formula" like this
=AVERAGE(IF(SurveyResponses!A2:A7=A2,SurveyResponses!B2:D7))
You need to confirm that with CTRL+SHIFT+ENTER so that curly braces appear around the formula in the formula bar. That formula will count any blanks as zeroes but ignore text values like NA
Easiest way to do this would be a pivot table. They look scary, but they're fairly easy to use. Rows = names, Columns = Q, Average for the answers.