Structured referencing: sum cells at intersection of current row and some columns - excel

I am using structured tables in Excel 2010.
In table "P" I have multiple columns labeled 1a, 1b, 1c, 2a, 2b, 3a ...
The data are some numeric values.
In table "Q" I would like to have columns labeled 1, 2, 3 and each colum should have a sum of the values of table "P" in the corresponding group of columns. That is:
Column 1 should sum up the contents in columns labeled 1a, 1b, 1c
Column 2 should sum up 2a, 2b
Column 3 should sum up 3a, ...
All this should be done on per-row basis.
As a start, I was trying to actually do something simpler and reference a single cell in the current row. By reading the documentation I tried the following:
=P[[#This Row],[1a]]
but even this is causing some formula error which I don't understand.
Update:
With SUMIF I managed to get very close to what I want:
=SUMIF(P[#Headers]; "1a"; P[#])
and if I could somehow grab the tested header value and plug it into the SEARCH function - I would be able to accomplish what I need.

You could perhaps use SUMPRODUCT:
=SUMPRODUCT((LEFT(P[#Headers],P[#Headers]-1)="1")*P)
(LEFT(P[#Headers],P[#Headers]-1)="1") will return an array which will say what headers in table P has 1 as the first integer. This will then be used to determine which columns in the table to sum up.
LEFT(P[#Headers],P[#Headers]-1) returns the integer from your headers. It basically removes the last character from each header and compares it to 1 in the above case.

Related

All combinations of 4 out of 7 columns with totals using excel

I have 7 columns to choose from and I need to pick 4 of those columns and generate a total for each row. I also need every combination of 4, which means I'll have 35 new columns with the totals for each of those combinations showing in each row. I need the code for this and if it can be done only using Excel. Here is an image of the columns and the grayed ones are the 7 columns I'm talking about. My knowledge of Excel is very limited. There are over 1,500 rows if that matters.
multi step approach that is going to use some helper rows. there may be a more elegant formula that will do this, and much slicker options in VBA, but this is a formula only approach.
Step 1 - Generate List of Column Combination
To generate the list 4 helper rows will need to be insert at the top of your data. either above or below you header row. These 4 rows will represent the column number you are going to pick. To keep the math simpler for me I just assumed the 1 for the first column and 7 for the last column. those numbers will get converted to later to account for column in between in your spreadsheet. For the sake of this example The first combination sum will occur in column AO and the first helper row will be row 1. The first combination will be hard coded and it will seed the pattern for the remainder of column combinations. Enter the following values in the corresponding cells:
AO1 = 1
AO2 = 2
AO3 = 3
AO4 = 4
In the adjacent column a formula will be placed and copied to the right. It will automatically augment the bottom value by 1 until it hits its maximum value at which point the value in the row above will increase by 1 and the the value of the current will be 1 more than the cell above. This will produce a pattern that covers all 35 combinations by the time column BW is reached. Place the formulas below in the appropriate cell and copy to the right:
AP1
=IF(AO2=5,AO1+1,AO1)
AP2
=IF(AO2=5,AP1+1,IF(AO3=6,AO2+1,AO2))
AP3
=IF(AO3=6,AP2+1,IF(AO4=7,AO3+1,AO3))
AP4
=IF(AO4=7,AP3+1,AO4+1)
Step2 - Sum The Appropriate Columns
I was hoping to use a some sort of array type operation to read through the column reference numbers above, but I could not get my head around it. Since it was just 4 entries to worry about I simply added each reference manually in a SUM function. Now the important thing to note is that we will be using the INDEX function over the 13 columns that cover the range of your columns so to convert the index number we figured out above, to something that will work to grab every second row, the number that was calculated will be multiplied by 2 and then 1 will be subtracted. That means 1,2,3,4 for the first column combination becomes 1,3,5,7. You can see this in the following formula. Place the following formula in the appropriate cell and copy down and to the right as needed.
AO5
=INDEX($AB5:$AN5,AO$1*2-1)+INDEX($AB5:$AN5,AO$2*2-1)+INDEX($AB5:$AN5,AO$3*2-1)+INDEX($AB5:$AN5,AO$4*2-1)
pay careful attention to the $ which will lock row or column reference and prevent them from changing as the formula is copied.
Now you may need to adjust the cell references to match your sheet.

Excel Data Manipulation with alphanumberic data

I have two columns in Excel. We can say that column 1 and column 2. Both columns have alphanumeric data i want to minus column 1 from column 2. How can i do that.
Example:
column 1 column two result column
ab ab ad
ac ac
ad
Thanks
There are more sophisticated/cleaner ways to do this, but I'd enter this formula into column C (update your ranges accordingly to capture each list), and then sort the result column:
=IF(COUNTIF($A$1:$A$8,$B$1:$B$4)=0,A1,"")
This compares the list in $A$1:$A$8 to the list in $B$1:$B$4 and places the "differences" in the result column C. I'm assuming that sorting is permissible. But like I said, there are VBA solutions that could do this a little more cleanly.

Index/Match Multiple Criteria, Perform Calculation for Each Match

I have two columns in a table that are known as S and D, where S is a date, and D is a duration.
E.g.:
'S' Column
January
February
March
April
'D' Column
60
30
45
30
On a separate sheet, imagine that Row 1 contains a sequence of dates (variable, depends on user menu selection).
Row 2 requires the following calculation:
[(x - s1)/d1 + (x-s2)/d2 + ... + (x-sn)/dn] / n
...where "x" is any date along Row 1.
The calculation would only be done when multiple criteria are matched.
My initial attempt involved creating a separate table, but I think this can be done in a one-cell formula in Row 2. I don't think a sum(index(match)) type would work here considering d1, d2, ..., dn are denominators with different values.
Here is an example attempt:
=SUM((SelectedDate-INDEX(Table[StartDates],MATCH(Criteria1&Criteria2,Range1&Range2,0))/INDEX(Table[Durations],MATCH(Criteria1&Criteria2,Range1&Range2,0))))
It may be important to note that I am able to do this in a two-step fashion. First, I create a table that does the calculation on each row. Then, I reference the table. It would be nice if I can eliminate the need of a "calculation table" in favour of an array-type formula.
I took a guess before most of the comments and suggest the following mainly in case it provides ay ideas or is of help in specifying the requirement more closely. This is "two-step" because the average formula is separate from that for each column, so I appreciate may well be not what is required.
Assuming S and D are labelled data in Sheet2 ColumnsA:B.
Assuming Row1 data rows are labelled in ColumnA.
Assuming dates are not strings (eg January is actually Jan 1) and the differences are in days and always positive, etc.
=(B$1-CHOOSE(COLUMN(),Sheet2!$A1,Sheet2!$A2,Sheet2!$A3,Sheet2!$A4))/CHOOSE(COLUMN(),Sheet2!$B1,Sheet2!$B2,Sheet2!$B3,Sheet2!$B4)
in Row2 to suit and if four data columns, in F2 and copied down to suit :
=AVERAGE(B2:E2)

matching multiple values from separate sheets in excel

I have two sheets of data I need to match and transfer values with.
First two columns 1A & 1B
Column 1A contains all unique numbers (these are invoice numbers that we bill out to our customers)
Column 1B contains revenues when we receive payment for these jobs.
second two columns 2A & 2B
I have started to scan our check reports and transfer the data into a simple two column excel sheet (2A & 2B) Column A contains invoice numbers that are also contained in column 1A, column 2B contains the data I want to be transferred into column 1B for each corresponding match between columns 1A & 2A.
I have done some digging and cannot seem to find a simple solution to my problem.
VLOOKUP is the solution.The formula to do this would go into sheet 1, Col B , Row 2 (Assuming you have a headers in row 1).
=VLOOKUP(A2, sheet2!A:B,2,false)
The formula works like so
VLOOKUP(lookup_value,table_array,col_index_num,range_lookup)
-lookup_value = a cell you want to lookup
-table_array = a range of columns with the lookup column in col1
-index_num = the column you want to return as an int ( in this case column 2)
-range_lookup = should be false to ensure an EXACT match

Finding matching value in sheet 2 and copy adjacent cells value in sheet 1

I have searched through many similar topics but could find nothing that will do what I need.
I am trying to create a worksheet that will track scores for a darts game.
On Sheet 1 I have two columns that simply tracks each players throws from 501 down to 0
Row 25 is the amount remaining for each player.
In Sheet 2 I have 2 columns. The Column A contains scores that you can check out on, and Column B contains the checkout e.g. (T20, T20, D18). So if the value in row 25 of Sheet 1 matches any of the values in Column A of sheet 2, the I want to display the Value of Column B in the matching row on Sheet 2 Underneath the remaining score on Sheet 1.
Can anyone point me in the right direction?
not sure what you mean exactly, but this formula in row 26 should do the trick:
=index('Sheet 2'!$B:$B;match(A25;'Sheet 2'!$A:$A;0))
if your list separator is comma ,, use that instead of semicolon ;
you might want to use 1 as the third argument of match function, if you want to display the checkout according to the nearest match that is bigger than the number in row 25 and the column A in Sheet 2 is sorted in ascending order (1-9)
or -1 if you want the nearest match that is smaller and column A is sorted in descending order (9-1)
You can use this:
=IFERROR(VLOOKUP(A4, Sheet2!$C$2:$E$65535, 3, FALSE),0)

Resources