I have a table in Excel that looks like this:
Name QuestionID Answer
A 1 Shoes
B 1 Coats
A 2 1983
B 2 1978
I want to create a table that Looks like this:
Name 1 2
A Shoes 1983
B Coats 1978
I've tried creating a pivot table, where "Name" is the row, "QuestionID" is a column, and "Answer" is the value. But values need to be aggregated, so I wind up with something numerical, instead of just the text or numbers in "Answers." I'm not clear on how to just display just the values, and not some processed version of the values.
Any help would be really appreciated!
This is why I never use Pivot Tables...they never seem to do what I need them to do.
Assuming that you can create a unique distinct list for the Header row & Name column manually, or auto-magically (see unique distinct list)
You could just use the following formula inside the table to do a lookup:
=INDEX($C$2:$C$5,SUMPRODUCT(($A$2:$A$5=$E2)*($B$2:$B$5=F$1)*ROW($C$2:$C$5))-ROW($C$1))
Where
Source Table is in A1:C5
Result Table - Name Column is E1:E3
Headers (for Questions) are in cells F1:G1
If you break it up, it's just an INDEX table lookup
=INDEX($C$2:$C$5,SOME_ROW)
Where SOME_ROW is determined by
SUMPRODUCT(($A$2:$A$5=$E2)*($B$2:$B$5=F$1)*ROW($C$2:$C$5))
Breaking the SUMPRODUCT down, we're just creating set of lists, of 1's & 0's (or True/False) for the search criteria.
The first column to match the Name is determined by ($A$2:$A$5=$E2)
The second column to match the Question is determined by ($B$2:$B$5=F$1)
Multiplying the two lists together, when Name = A & Question =1 you get
(A,B,A,B) * (1,1,2,2)
(1,0,1,0) * (1,1,0,0) = (1,0,0,0)
The third list (that we are going to multiply the above result with) from the SUMPRODUCT, is the actual Row; it's determined by ROW($C$2:$C$5), so we get:
(1,0,0,0) * (2,3,4,5) = (2,0,0,0)
Now we SUM the PRODUCTS of the result:
2 + 0 + 0 + 0 = 2
So the actual result is in Row 2; Yes!
...but we have a problem; in the INDEX function, the the Array starts on Row 2, so if we specify the 2 for the row number, we'll actually get the value from row 3 because of the starting row offset.
This is where -ROW($C$1) comes in; to fix the row offset. It should point to a cell in the header row.
It's much easier then it looks...
Related
I have two workbooks that I need to pull data from workbook1, to workbook2. The identifier to achieve such is empID Now for eachempID I need to show what location(s) they worked. So sample data looks like this
Workbook1
empID.....Name....Address...City...State....Zip
1
2
3
4
5
Workbook2
empID.......locationworked
1 12
2 33
1 11
4 22
3 9
1 55
5 19
2 76
1 99
I have used this formula to return the data to a different cell for each empID
=IFERROR(INDEX($B$2:$B$8, SMALL(IF($A$11=$A$2:$A$8, ROW($A$2:$A$8)-ROW($A$2)+1), ROW(1:1))),"" )
But I want to create a Comma Separated list and put everything in one cell, like so
1 11,12,55,99
2 33,76
etc
Is there a way to modify the syntax so that a comma separated list is created like in my desired output?
In workbook 2, I added this formula to column C
=IFERROR(VLOOKUP(A1,A2:$C$50,3,0)&","&B1,B1).
This assumes that your data goes as far down as row 50. Replace $C$50 with whatever row is last in your spreadsheet.
If this is a variable list, use
=INDIRECT("A2:C"&MATCH(TRUE,D:D="",0),1)
in place of the
A2:$C$50
however don't forget to use Ctrl + Shift + Enter to set the formula to an array.
Next, copy this formula down all rows. The VLOOKUP will work up the sheet. Then you can reference this list from your report sheet (I believe in this case its Sheet 1) with a VLOOKUP. it will automatically pick the first instance of each employee ID which contains the csv list.
I'd like to point out that whilst bad_neighbor's solution is quite accurate and reusable for future data changes, it is often preferable to avoid lookups where possible, and to store calculated results as values, since these aren't perfectly efficient and tend to slow down the sheet something awful given a larger quantity of data, for example when filtering / unfiltering. It's worse in older versions.
So, if this list formatting were part of a manual operation, and assuming the requirement is for each list item to be in ascending order (per the question's output), I'd do the following instead:
If workbook2's order is important, add an index of the rows (D1 := 1; D2 := D1 + 1; paste values).
Sort workbook2 by [A ascending, B descending], including index if present.
Apply this formula to column C - a fillup version of the lookup.
C1 := IF(A1=A2,C2&", "&B1,B1)
Copy-paste special values column C.
Lookup from workbook1 + copy-paste special values.
Optionally sort back according to original index (D) in workbook2.
I have a table with 2600+ rows, related to towns in my region and their population; each town has 11 rows, one for each age class (0-9, 10-19, and so on).
I need to get the sum of the population of each town; of course I can do it manually but it's a never ending job; I wonder if there's some kind of command that tells excel to do the sum every 11 rows and do it for all the towns.
I think it's a kind of loop but I have no idea about how to do it.
The problem can be reduced by using the SUMIF function. The question then becomes how to apply this to your dataset.
Assuming one of the columns in your 2600+ rows contains the town name (or another unique identifier), and you have a list of towns (or other unique identifier), the below method can be used.
The formula in E2 is =SUMIF(A:A,D2,C:C), and in E3 =SUMIF(A:A,D3,C:C). A to C is the list of all data, D is a list of towns.
For a VBA solution, you should be able to use a step in the loop.
So if you wish to step by 11 rows at a time.
Public Sub IterateRows()
Dim rData As Range, rPtr As Range
Dim dSum As Double
Dim i As long
Set rData = Sheet1.Range("A1:A1000")
For i = 1 To rData.Rows.Count Step 11
Set rPtr = rData(1).Resize(11).Offset(i - 1)
dSum = Application.WorksheetFunction.Sum(rPtr)
Next
End Sub
If you want a worksheet function solution, you will probably have to use the MOD operator and check for when the value is zero..
You can also try this manual method which is not a never ending job; i.e.:
in E11 put your formula as =SUM(C1:C11)
copy range E1:E11
select range E12:E2600 and paste special function
Do you have any reference columns? As in...say for example Column A has the Town Name, and Column B has the Age Class, and Column C has the values.
Going down the rows Column A will have repeating town names, yes?
Like this:
Town - Age Class - Pop
Wherever - 0-9 - 1000
Wherever - 10-19 - 2000
Wheverer - 20-29 - 2500
Assuming you have maintained the data structure (NO GAPS) a possible solution in Column D (or whatever column just make sure you change the references) could be (putting this in D2 and dragging it down the length of your sheet):
=IF(A1<>A2,SUM(INDIRECT("C"&ROW(A2)&":C"&SUMPRODUCT(MAX((A:A=A2)*(ROW(A:A)))))),D1)
This works if you have any amount of rows per town, so long as you SORT by town name so the same names are next to each other in the list and there are no gaps.
In the above test data set I subtracted 250 from each Values count per Town going down (each class has 250 less than the previous city) just to show some variation in the output...you can see each city has 2750 (250 * 11) less pop than the previous.
Basically it builds an array with a starting position of "not the town above" in the first row it encounters a new town name to an ending position of "last (max) position of new town in same list" so that is how it doesn't matter how many rows you have per town. From 1 to memory limit basically, I think. :)
ALTHOUGH, this also works:
=SUMIF(A:A,A2,C:C)
Yep. Not kidding just drag that down Column D...
Assuming the following structure
This is a very easy task using a pivot table.
For LibreOffice Calc:
Just select the complete data area including the column headers (in my example: A1:C13);
Menu Data -> Pivot Table;
Current selection;
Following settings for Pivot table:
(drag the Town field into the Row Fiels area, and the Count field into the Data fields area. LO Calc will offer to calculate the Sum of the count entries by default).
Hit OK - the resulting pivot table will look like this:
This solution has the advantage that the source data area hasn't to be sorted by town, and it doesn't matter if some towns don't have nine value rows each. Additionally, you don't need any formulas.
EDIT:
You can work with the contents of the pivot table the same way as with calculated results. For example, you could use the pivot table values to calculate the sum for some of the towns (in my example, calculate the sum for town B and C based on the pivot table values B3 and B4 respectively):
You could do this with the MOD function, which gives the remainder of division. You could look at each row number and if its MOD of 11 equals zero, then it's the row you're looking for.
I am counting 10 items in each section in your example so I'm not sure I completely understand. Let's assume you need to sum every row that ends in a 9 (A9, A19, A29, etc.). You can replace the 9's below with an 11.
=ROW(A9) gets you the row number.
=MOD(ROW(A9),9) gets you a TRUE or false on weather that number is divisible by 9. If it is a multiple of 9, it will return the number 0.
Now use the SUM function and hit CONTROL+SHIFT+ENTER to complete it. Note that the formula bar indicates that this is an array function by using curly braces. You don't need to type those in yourself.
{=SUM(A1:A9*(MOD(ROW(A1:A9),9)=0))}
In sheet 1, I have a list of dates in Column A in chronological order. There are values corresponding to this list in Column B. There is another list of dates in sheet 2 and I want to add values from sheet 1 to these dates.
Sheet 1.
**Column A Column B
DATE Amount**
1. 10/01/2015 25,60,000
2. 10/02/2015 26,80,000
3. 01/03/2015 21,55,000
4. 30/03/2015 24,60,500
5. 30/04/2015 28,20,000
6. 30/06/2015 19,00,000
Sheet 2.
Column A Column B
1. 21/02/2015 21,55,000
2. 15/01/2015
3. 20/05/2015
4. 25/04/2015
For example: I need to look up 21/02/2015 in sheet 1 and column A and return the value corresponding to the next available date. So for 21/02/2015 I need the value corresponding to the next date available which is 01/03/2015 and the value is 21,55,000. If its 15/01/2015 I need the value of 10/02/2015 i.e. 26,80,000
What formula could I use for this?
You could use VLOOKUP, but it has some issues. So it is better to use INDEX and MATCH combination. In your case try this
=INDEX('Sheet 1'!$B:$B,MATCH(A1,'Sheet 1'!$A:$A,-1))
Sorry, my previous answer works only for descending order. Try this instead
=INDEX('Sheet 1'!$B:$B,MATCH(TRUE,('Sheet 1'!$A:$A-A1)=MIN(IF('Sheet 1'!$A:$A-A1>=0,'Sheet 1'!$A:$A-A1)),0))
Explanation: I hope that INDEX and MATCH are well explained in Office Support.
About the condition:
('Sheet 1'!$A:$A-A1)=MIN(IF('Sheet 1'!$A:$A-A1>=0,'Sheet 1'!$A:$A-A1))
What it means?
'Sheet 1'!$A:$A-A1
results in a difference between the value in the cell A1 and the cell in A column in Sheet 1.
MIN(IF('Sheet 1'!$A:$A-A1>=0,'Sheet 1'!$A:$A-A1))
says that if the difference is non-negative ('Sheet 1'!$A:$A-A1>=0), find the minimum of such numbers (MIN function).
And if these numbers are equal (MATCH function), then pick the corresponding number in column B (INDEX('Sheet 1'!$B:$B,...)).
Apology: In my previous answers I swapped the columns of your example. I hope it is now correct.
You can use vlookup with True rather than the widely used form with False
As ExcelEfendisi said you can use vlookup with range lookup enabled. A simple way to get the value at the next date rather than the prior one would be to push all the amount values down one row, but to avoid that it might be better to repeat the index values - like this
1 10/01/15 25,60,000 1
2 10/02/15 26,80,000 2
3 01/03/15 21,55,000 3
4 30/03/15 24,60,500 4
5 30/04/15 28,20,000 5
6 30/06/15 19,00,000 6
Then you can use two vlookups, the first one to get the index of the row with the date prior to the date you are interested in and a second one to extract the balance value for the subsequent date - not very elegant but it would work
Try this formula (enter in Sheet2 cell B2 then copy till the last record)
=INDEX(Sheet1!$B:$B,1+MATCH($A2,Sheet1!$A:$A,1),1)
As data is sorted in ascending order use MATCH with match type 1 (less than) to obtain the row above the high next item, then add 1 and the result is the high next row, use this row to get the corresponding record from the column B with formula INDEX
I am trying to build a macro that will allow me to automatically fill out the cells in a column based on 2 criteria, which are the county and the project type, both of which are their own column names. The column to be filled out will be called "Frequency Band", which will have a static range of 12 possible values.
For example, if the County is "Bergen" and the Project Type is "2", then the Frequency Band will be "800Mhz". If it is the same county (Bergen) but the project type is "3", then the frequency band will be "1900MHz".
I currently have the list of Frequency Bands listed in another worksheet (Just call it sheet 2, cells E2 – E13), so I imagine that the outline of the VBA code would look something like:
If County(A) = Lee AND Project Type(B) = 2 Then Frequency Band(C) = 800Mhz(E3)
Else if Project Type = 3 Then Frequency Band = 1900MHz
Etc., Etc. for each county
Since I’ve never coded in VBA before and have no idea of its syntax, I don't really know where to begin with a formula like this. Could anyone help get me started?
Here is one way it would work with a formula.
In cells G1:K6 there is a table with your stored data (could also be on another sheet)
Column A you put in a country, column B you put in a project type (would be good if you validated against your source data.
Column C is your lookup function
'=INDEX($H$2:$K$6,MATCH(A2,$G$2:$G$6,0),MATCH(B2,$H$1:$K$1,0))
Index takes 3 main inputs:
the array (H2:K6) which is the actual frequency values
a row number in this array, and a column number in the array
For the row number lookup your country in the list you have (g2:g6) and it will tell you it is the x number in the array which corresponds to the row in the index array
Same thing with the column and project type.
There is a ton of information on the net about index and match if you need more information.
Highlighing is to show which values the formula has picked in my three examples below.
This is a confusing request.
I have an excel tab with a lot of data, for now I'll focus on 3 points of that data.
Team
Quarter
Task Name
In one tab I have a long list of this data displaying all the tasks for all the teams and what Quarter they will be on.
I WANT to load another tab, and take that data (from the original tab) and insert it into a non-list format. So I would have Quarters 1,2,3,4 as columns going across the screen, and Team Groups going down. I want each "task" that is labeled as Q1 to know to list in the Q1 section of that Teams "Block"
So something like this: "If Column A=TeamA,AND Quarter=Q1, then insert Task Name ... here."
Basically, if the formula = true, I want to print a list of those items within that team section of the excel document.
I'd like to be able to add/move things around at the data level, and have things automatically shift in the Display tab. I honestly have no idea where to start.
If there is never a possibility that there could be more that 1 task for a given team and quarter, then you can use a formula solution.
Given a data setup like this (in a sheet named 'Sheet1'):
And expected results like this (in a different sheet):
The formula in cell B2 and copied over and down is:
=IFERROR(INDEX(Sheet1!$C$2:$C$7,MATCH(1,INDEX((Sheet1!$A$2:$A$7=$A2)*(Sheet1!$B$2:$B$7=B$1),),0)),"")
I came across this situation. When I have to insert the values into a table from an Excel sheet I need all information in 1 Column instead of 2 multiple rows. In Excel my Data looks like:
ProductID----OrderID
9353510---- 1212259
9650934---- 1381676
9572474---- 1381677
9632365---- 1374217
9353182---- 1212260
9353182---- 1219361
9353182---- 1212815
9353513---- 1130308
9353320---- 1130288
9360957---- 1187479
9353077---- 1104558
9353077---- 1130926
9353124---- 1300853
I wanted single row for each product in shape of
(ProductID,'OrdersIDn1,OrderIDn2,.....')
For quick solution I fix it with a third column ColumnC to number the Sale of Product
=IF(A2<>A1,1,IF(A2=A1,C1+1,1))
and fourth Column D as a placeholder to concatenate with previous row value of same product:
=IF(A2=A1,D1+","&TEXT(B2,"########"),TEXT(B2,"########"))
Then Column E is the final column I required to hide/blank out duplicate row values and keep only the correct one:
=IF(A2<>A3,"("&A2&",'"&D2&"'),","")
Final Output required is only from Column E
ProductID Order Id Sno PlaceHolder Required Column
9353510 1212259 1 1212259 (9353510,'1212259'),
9650934 1381676 1 1381676 (9650934,'1381676'),
9572474 1381677 1 1381677 (9572474,'1381677'),
9632365 1374217 1 1374217 (9632365,'1374217'),
9353182 1212260 1 1212260
9353182 1219361 2 1212260,1219361
9353182 1212815 3 1212260,1219361,1212815 (9353182,'1212260,1219361,1212815'),
9353513 1130308 1 1130308 (9353513,'1130308'),
9353320 1130288 1 1130288 (9353320,'1130288'),
9360957 1187479 1 1187479 (9360957,'1187479'),
9353077 1104558 1 1104558
9353077 1130926 2 1104558,1130926 (9353077,'1104558,1130926')
You will notice that final values are only with the Maximum Number of ProductSno which I need to avoid duplication ..
In Your case Product could be Team and Order could be Quarter and Output could be
(Team,Q1,Q2,....),
Based on my understanding of your summary above, you want to put non-numerical data into a grid of teams and quarters.
The offset worksheet function will work well for this in conjunction with the match or vlookup functions. I have often done this task by doing the following steps.
In my data table, I have to concatenate the Team and quarter columns so I have a unique lookup value at the leftmost column of your table (Note: you can eventually hide this for ease of reading).
Note: You will want to name the input range for best formula management. Ideally use an Excel Table (2007 or greater) or create a dynamically named range with the offset and CountA functions working together (http://tinyurl.com/yfhfsal)
First, VLOOKUP arguments are VLOOKUP(Lookup_Value,Table_Array,Col_Index_num,[Range Lookup]) See http://tinyurl.com/22t64x7
In the first cell of your output area you would have a VLOOKUP formula that would look like this
=Vlookup(TeamName&Quarter,Input_List,Column#_Where_Tasks_Are,False)
The Lookup value should be referencing cells where you have the team names and quarter names listed down the sides and across the top. The input list is from the sheet you have the data stored. The number three represents the column number the tasks are listed in your source data, and the False tells the function it will only use an exact match in your putput.