Conditionally sum specific columns in multiple column table - excel

I have a timetable that shows every day of the year. The columns are headed with month names and h (for hour). If I mark a day with a label I put a number on the h column right next to it. These numbers should be summed up whenever the appropriate label is found.
Example of my timetable
So the formula (not query!) should look for a specific label on the whole timetable and sum all numbers right next to it in one cell.
I've tried several solutions but I guess I just don't understand the mechanism of array formulae to achieve a solution and even the SUMIFS function doesn't get me anywhere.

=SUMIF(B4:Y34,"WM",C4:Z34)
works for me. Don't know why sumifs didn't for you but then you haven't said what your problem was with it.

Related

Sum.if, without nesting 12 sum.if functions

I have a problem with an excel function, i "inherited" from a former colleague.
I have the two tables below:
My goal is to get the green field in Table 2 to show the sum of Person1s earnings from January to December. If months was =11 in Table 2, it should show the sum of Person1s earnings from January to November.
My current formular is a lot of nested "If" and "Sum.if" functions, but i wish to shorten it. Is it possible. I tried to say the sum area in the Sum.If to be all columns with data, but it still just returns the one from january (the first one it finds, i guess)
I hope someone can help me! Sorry for my bad english, but i'm not a native speaker
Best regards
Edit: Current formula by request
=IF(A2=0;0;IF($I$1=1;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L);IF($I$1=2;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M);IF($I$1=3;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M)+SUM.IF('Earnings'!A:A;A2;'Earnings'!N:N);IF($I$1=4;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M)+SUM.IF('Earnings'!A:A;A2;'Earnings'!N:N)+SUM.IF('Earnings'!A:A;A2;'Earnings'!O:O);IF($I$1=5;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M)+SUM.IF('Earnings'!A:A;A2;'Earnings'!N:N)+SUM.IF('Earnings'!A:A;A2;'Earnings'!O:O)+SUM.IF('Earnings'!A:A;A2;'Earnings'!P:P);IF($I$1=6;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M)+SUM.IF('Earnings'!A:A;A2;'Earnings'!N:N)+SUM.IF('Earnings'!A:A;A2;'Earnings'!O:O)+SUM.IF('Earnings'!A:A;A2;'Earnings'!P:P)+SUM.IF('Earnings'!A:A;A2;'Earnings'!Q:Q);IF($I$1=7;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M)+SUM.IF('Earnings'!A:A;A2;'Earnings'!N:N)+SUM.IF('Earnings'!A:A;A2;'Earnings'!O:O)+SUM.IF('Earnings'!A:A;A2;'Earnings'!P:P)+SUM.IF('Earnings'!A:A;A2;'Earnings'!Q:Q)+SUM.IF('Earnings'!A:A;A2;'Earnings'!R:R);IF($I$1=8;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M)+SUM.IF('Earnings'!A:A;A2;'Earnings'!N:N)+SUM.IF('Earnings'!A:A;A2;'Earnings'!O:O)+SUM.IF('Earnings'!A:A;A2;'Earnings'!P:P)+SUM.IF('Earnings'!A:A;A2;'Earnings'!Q:Q)+SUM.IF('Earnings'!A:A;A2;'Earnings'!R:R)+SUM.IF('Earnings'!A:A;A2;'Earnings'!S:S);IF($I$1=9;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M)+SUM.IF('Earnings'!A:A;A2;'Earnings'!N:N)+SUM.IF('Earnings'!A:A;A2;'Earnings'!O:O)+SUM.IF('Earnings'!A:A;A2;'Earnings'!P:P)+SUM.IF('Earnings'!A:A;A2;'Earnings'!Q:Q)+SUM.IF('Earnings'!A:A;A2;'Earnings'!R:R)+SUM.IF('Earnings'!A:A;A2;'Earnings'!S:S)+SUM.IF('Earnings'!A:A;A2;'Earnings'!T:T);IF($I$1=10;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M)+SUM.IF('Earnings'!A:A;A2;'Earnings'!N:N)+SUM.IF('Earnings'!A:A;A2;'Earnings'!O:O)+SUM.IF('Earnings'!A:A;A2;'Earnings'!P:P)+SUM.IF('Earnings'!A:A;A2;'Earnings'!Q:Q)+SUM.IF('Earnings'!A:A;A2;'Earnings'!R:R)+SUM.IF('Earnings'!A:A;A2;'Earnings'!S:S)+SUM.IF('Earnings'!A:A;A2;'Earnings'!T:T)+SUM.IF('Earnings'!A:A;A2;'Earnings'!U:U);IF($I$1=11;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M)+SUM.IF('Earnings'!A:A;A2;'Earnings'!N:N)+SUM.IF('Earnings'!A:A;A2;'Earnings'!O:O)+SUM.IF('Earnings'!A:A;A2;'Earnings'!P:P)+SUM.IF('Earnings'!A:A;A2;'Earnings'!Q:Q)+SUM.IF('Earnings'!A:A;A2;'Earnings'!R:R)+SUM.IF('Earnings'!A:A;A2;'Earnings'!S:S)+SUM.IF('Earnings'!A:A;A2;'Earnings'!T:T)+SUM.IF('Earnings'!A:A;A2;'Earnings'!U:U)+SUM.IF('Earnings'!A:A;A2;'Earnings'!V:V);IF($I$1=12;SUM.IF('Earnings'!A:A;A2;'Earnings'!L:L)+SUM.IF('Earnings'!A:A;A2;'Earnings'!M:M)+SUM.IF('Earnings'!A:A;A2;'Earnings'!N:N)+SUM.IF('Earnings'!A:A;A2;'Earnings'!O:O)+SUM.IF('Earnings'!A:A;A2;'Earnings'!P:P)+SUM.IF('Earnings'!A:A;A2;'Earnings'!Q:Q)+SUM.IF('Earnings'!A:A;A2;'Earnings'!R:R)+SUM.IF('Earnings'!A:A;A2;'Earnings'!S:S)+SUM.IF('Earnings'!A:A;A2;'Earnings'!T:T)+SUM.IF('Earnings'!A:A;A2;'Earnings'!U:U)+SUM.IF('Earnings'!A:A;A2;'Earnings'!V:V)+SUM.IF('Earnings'!A:A;A2;'Earnings'!W:W);"")))))))))))))
In B16, enter formula :
=SUM(OFFSET(B2,MATCH(A16,A3:A9,0),,,C12))
SUMIF is used to add the contents of a single column that match the criteria.
To achieve what you want, try this:
To shorten the formula significantly
=SUMPRODUCT(($A$3:$A$9=$A$14)*(B3:K9))
I have guessed your row and column numbers, but if you can't get it working just post your row and column headings and I will troubleshoot it.
Alternatively, if you would like to add another table with cumulative earnings, you could do it quite easily.
To provide cumulative earnings for each month for each person
For example, in B15 (or whatever the reference, we can't see your row/column number) you could have "Cumulative Jan", then fill right for a column for the cumulative earnings for each month. In that case B15 would say:
=SUM($B3:B3)
Then fill right and down.
This gives you cumulative earnings for any month for any person, in a table.
You could then do a lookup to that table if you wanted to, to return the matching value given the two inputs of person and month number.

Excel Formula or function that returns the Nth value from a dynamically generated grouping of cells

I am trying to assemble a index/match combination and am having trouble figuring out how to make it work. I have experience with a lot of the formula types in excel, but unfortunately I am pretty ignorant when it comes to these functions.
I will explain what I am trying to do first, but I have attached 3 images at the end that will probably make things more clear.
In order to identify the specific values I want, I am having to use helper cells. These helper cells are denoted with the (helper) tag in the pictures. These cells go through and grab the adjusted closing price of the stock (column A) at the beginning (column C) and the end (Column D) of a dynamically calculated period.
I would like to consolidate these values into numerical order in columns F and G. The thought is that the first non zero number in C/D is belongs to the first predefined period and should go into columns F/G beside the #1 (column E). This gets carried on through all of the periods (ex: 2nd non zero goes beside the number 2, third nonzero number goes beside the number 3 etc.)
This is just an example of one stock. I need the function or formula to be dynamic enough to work on a wide variety of distributions. Sometimes there are up to 100 dynamically calculated periods within the stock analysis.
Below are the images that should provide more clarity
Image 1 is an example of what the data looks like
Image 2 is a crudely drawn example of how I would like the data to move
Image 3 is the desired result
Image 1
Image 2
Image 3
Updated image for Scott Craner showing out of order results
Please let me know if I can clarify any confusion.
If you just need to return the first value of each period (column C) and the last value of each period (column D), you could use index match and lookup to do this without even using helper columns.
Try this in cell F2
=INDEX(A2:A50,MATCH(E2,B2:B50,0))
And this in cell G2
=LOOKUP(E2,B2:B50,A2:A50)
Depending on much variance is in your overall number of rows, you could use indirect references in the formulas to dynamically update the ranges.
Example:
=INDEX(A2:INDIRECT("A"&COUNTA(A:A)),MATCH(E2,B2:INDIRECT("B"&COUNTA(A:A)),0))
You will need to open macro. Then do the following in recorded macro.
+ Filter only non-null value in C/D
+ Select whole column in C/D then copy the whole column
+ Turn off Filter
+ Paste the whole C/D in F/G
+ Stop macro
Gook Luck
Put this formula if F2:
=INDEX(INDEX(C:C,MATCH($E2,$B:$B,0)):INDEX(C:C,MATCH($E2,$B:$B,0)+COUNTIF($B:$B,$E2)-1),MATCH(1E+99,INDEX(C:C,MATCH($E2,$B:$B,0)):INDEX(C:C,MATCH($E2,$B:$B,0)+COUNTIF($B:$B,$E2)-1)))
Copy over one column and down the list.

Comparing dates in two columns with matching criteria

I'm trying to fill out a sheet with a somewhat complicated criteria, I have four columns I'm interested in, however the columns are mixed into a much larger table, sorry vlookup :(
There are two columns that contain an ID# and a Category, one column with date and time stamp, and one that MAY contain a date and time stamp. (Column1,2,3,4 respectively)
Column 3 is when an action took place, Column 4 is the next time that action with the same ID# and Category has to have been completed by.
Essentially I need a cell(s) that will check for a date in Column 4, if there is one, find the next value in Column 3 that is greater than that of column 3 in the row with the value in Column 4, AND has the same ID, AND Category and compare them to see if it was done on time, preferably also by how much if it was late.
I'm able to find it almost with:
{=MAX(IF([#[Column 2]]=[Column 2],[Column 4]))}
Entered as an array formula, however that will only give me the last time that Category was given a "Next Due Date" and similarly with Column 1 replaced for Column 2 in the code sample above, I only get the last time that ID# was given a "Next Due Date".
As some Event ID# can be around for many days, and can run concurrently with others there's no guarantee all IDs will be grouped, nor Categories within those IDs.
It appears any attempts to add an AND(.. function break the array, though I'm not positive I'm not just messing up the placement of it.
It's perfectly fine if the solution involves creating helper cells.
The table is sorted chronologically by column 3 with the latest date at the top if that's any help.
TYVM for even taking the time to read this :)
Edit 1:
Sample Data
I've included an image with some sample data, to clarify the awkward sentence above. The orange arrows are pointing to two dates that would be compared and the event was late. the Green points to a group that was on time.
the categories are
Those two are being compared because each set has the same category, and ID. I hope that clears it up :)
You could try this formula (goes into column E):
=IFERROR( IF($D2<>"", LOOKUP(2,1/($F1:$F$2=$F2),$C1:$C$2), ""), "")
Very important here are the $ signs, as the searched area is supposed to move with the row. (Note: this formula goes into E2. You then copy > pastespecial (only Formulas) it into the rest of the column.)
My table looks like this:
A B C D E F
ID Category Start-date Due-Date Completion-Date ID+Cat. (Helper column)
The formula in F is simply =$A2 & $B2. The data starts in Row 2.
You will need to replace the columns with yours.
Please let me know if this is what you were looking for.

Return a value relative to every instance of a search term

I have a spread sheet populated with dates (Months) and revenue figures. The sheet is structured with numerous tables all containing these month-revenue pairings but they are not all in the same columns.
I need to be able to search the whole range of cells for a given month and then each time the month is found I need to look across for the revenue figure (5 cells to the right) and return the answer.
The answer returned needs to give the total figure for all instances of the search term.
VLookup won't work because there are multiple tables and they are not all lined up.
Any advice would be very gratefully received.
Thanks
You should use a VBA script for that, IMHO this is not possible to do in a formula. Here is a rough outline what you need to do:
Define an array of the month names as they appear in you sheet
Iterate this array and for each month name find all cells containing it (this might help)
Iterate all cells of each month and do your calculation based on this cell (find a cell with a certain offset or whatever)
If you cen provide a more specific description of your problem (preferably with example data/images), maybe we can give you a more specific answer.

Excel VBA 2010 - worksheet.subtotal function sum and average in the same row

I am creating a macro which takes data from an Oracle database, which means that the number of rows can vary depending upon the result. In this macro, I am using the worksheet.subtotal function, which sums up on a number of columns when the group changes. This all works, but the problem that I am facing are that a few of the columns need to be average.
Searching around I have not been able to find a solution where you can have both average and sum in the same row. I do not wish to have a situation where the user has to manually intervene to change each column for each group.
Is there away where you can have both average and sum in the same row?
AFAIK you cannot use both i.e Sum and Average together in Subtotal but don't loose heart :) Here is an alternative.
Let's say you have two columns. In one you want Sum and the other you want Average. In your code, set Sum for both columns. When the report is generated, simply highlight the column where you want Average and simply find and replace subtotal(9 with subtotal(1 using CTRL + H If you don't want to do it manually then you can do the Find and Replace in code as well ;)
This would work as Sum and Average have the same structure.
=Sum(<Range>)
=Average(<Range>)

Resources