How to average an entire column but ignoring the header - excel

I feel like this should be simple and my notation is just wrong, I know if i want to sum the entire column I can use this formula:
=AVERAGEIF(C:C, "<> ")
(I'm using "<>" as i need to ignore blanks)
How do i offset it by one row? I want it to start at C2 bu excel doesn't like
=AVERAGEIF(C2:C, "<> ")
Many thanks!

AVERAGE ignores text and blanks so,
=average(c:c)
... should be the same as,
=averageif(c2:index(c:c, match(1e99, c:c)), "<>")
(unless the header in C1 is numeric)

Related

match two columns and concatenate them

I have column A and B, i want to concatenate A with B values into c column using formula but need help. The problem is, if column B has more than two colors, then the formula breaks. I'm not quit sure how to fix the formula to support more than 2 colors which will likely happen on my worksheet. Here's the formula:
=IF(AND(A1="---",B1="---"),"---",IF(A1="",CONCATENATE(OFFSET(A1,-1,0)," - ",B1),CONCATENATE(A1," - ",B1)))
Try:
C1: =CONCATENATE(MAX($A$1:A1),"-",B1)
and fill down.
To account for the "---" entries:
C1: =IF(AND(A1="---",B1="---"),"---",CONCATENATE(MAX($A$1:A1),"-",B1))
Edit: Oh, and if the labels in Column A might not be in a nice numerical sequence, or might be text, you can use:
C1: =IF(AND(A1="---",B1="---"),"---",CONCATENATE(LOOKUP(2,1/(LEN($A$1:A1)>0),$A$1:A1),"-",B1))
Try this:
=INDEX(A:A,MATCH(1E+99,$A$1:A1))&"-"&B1

Looking up a value in a specified column

Something I've wanted to do quite a bit lately, and can't work out how to do, is MATCH in a column I pass as an argument. Essentially, I have a two dimensional array, and I want to be able to find the first occurrence of a given value in the nth column, for any given value of n, and return the row number it occurs at. Alternatively (and more-or-less equivalently), I want to be able to search in the column with a given column header. Is there any way to do this?
Effectively, I want to simulate the non-existent function =MATCH(lookup_value,lookup_array,lookup_column,[match_type])
I've kludged together a horrible bodge job using INDIRECT, which works, but offends me horribly.
=MATCH(lookup_value,INDIRECT("R"&<top of array>&"C"&<left of array>+<column reference>&":R"&<bottom of array>&"C"&<left of array>+<column reference>,FALSE),FALSE)
This formula should work for you and will avoid INDIRECT. Anytime you can avoid using Indirect, I recommend doing so.
=MATCH(lookup_value,INDEX(lookup_array,0,MATCH(lookup_header,array_headers,0)),0)
If you aren't looking up the column by column header and just have the column number, then it becomes easier:
=MATCH(lookup_value,INDEX(lookup_array,0,column_number),0)
You could do something like this:
Set findCell = ActiveSheet.Range("A:Z").Find(What:="term_to_search")
Will select a header based on your search term.
Set range = ActiveSheet.Range(findCell, findCell.Offset(DEF_MAX_ROWS, 0))
Set up a range which will search from that header down a whole column.
For column references beyond Z you might switch notation (Excel Options, Formulas, Working with formulas and check R1C1 reference style) and, assuming the value to be looked up is in 'A1' (R1C1) with the column number in 'A2' (R2C1) apply:
=MATCH(R1C1,INDIRECT("C"&R2C1,0),0)
to save some complexity in converting a string of two or three characters into the relevant column number.
Say we have a two dimensional array: B3:E17 and we wish to locate Happiness in the third column of that array.In G1 enter:
B3:E17
In G2 enter:
3
In G3 enter:
=ADDRESS(ROW(INDIRECT(G1)),COLUMN(INDIRECT(G1))+$G$2-1) & ":" & ADDRESS(ROW(INDIRECT(G1))+ROWS(INDIRECT(G1))-1,COLUMN(INDIRECT(G1))+$G$2-1)
This will display the address of that third column. Then in G4 enter:
=MATCH("Happiness",INDIRECT(G3),0)
For example:
You can specify a range in a formula using the INDIRECT function. So, for example, if you put the letter designation for the column you want to search in cell A75, you could use:
=MATCH("Value_To_Match", INDIRECT(A75 & ":" & A75), 0)
So, if the value in A75 is G, the string built up in the INDIRECT call is G:G, and the MATCH will look through column G for "Value_To_Match" and return the row number in which it's found.
Using this idea, you can put a formula into A75 that generates the column designation for the column you want to search. For example, if your column headers are all in row 1, and the header you want to search for is in A74, you can do:
=CHAR(MATCH(A74, 1:1, 0) + 64)
using the CHAR function to convert numbers into ASCII characters, so 65 becomes A, 66 becomes B, etc. Note that this will only work if you don't have columns past Z. You'd need a more fussy formula to do the right thing with AA, etc.
You can overcome the annoyances of dealing with column letters by using R1C1 notation instead, which you can activate by adding a second parameter of FALSE to the INDIRECT expression. Now, instead of specifying your column by a letter, you'll specify it using a number. This simplifies the column-finder in A75:
=MATCH(A74, 1:1, 0)
and also the INDIRECT expression in your overall MATCH:
=MATCH("Value_To_Match", INDIRECT("C" & A75, FALSE), 0)

Summing numeric portion of cell when alpha portion of cell is the same

I have a spreadsheet that has columns for dates and the values can be either "1v, .5v, 1p, .5p, 1s, .5s"
I have 3 columns in each row one for each letter "v, p and s". I want to be able to add the total of all cells in the range grouped by letter and then display the sum for each letter in it's respective column (v, p or c).
Here is an example of the sheet:
Name Vacation Personal Sick 1/5/15 1/6/15 1/7/15 1/8/15
Billy 1.5 1 0 .5v 1v 1p
It is the formula that goes in the vacation/personal/sick cell that I just can't figure out.
I went down the array formula route and came up with essentially the same formula as #Sancho.s :-
=SUM(LEFT($E2:$H2,LEN($E2:$H2)-1)*(RIGHT($E2:$H2)="v"))
You could modify it to take account of blanks:-
=SUM(IF($E2:$H2<>"",LEFT($E2:$H2,LEN($E2:$H2)-1)*(RIGHT($E2:$H2)="v")))
Perhaps this would be better, to ignore any mis-formatted cells:-
=SUM(IFERROR(LEFT($E2:$H2,LEN($E2:$H2)-1)*(RIGHT($E2:$H2)="v"),0))
These all have to be put in with Ctrl-Shift-Enter.
Assuming the range you posted starts at A1, use
=SUMPRODUCT((RIGHT($E2:$G2,1)="v")*LEFT($E2:$G2,LEN($E2:$G2)-1))
in B2. Change "v" and the range to use suitably.
Pro:
It is not an array formula. See why this may be important
Con:
I could not make it work with blank cells.
This "array entered" version will also allow blanks
=SUM(IF(RIGHT(E2:G2)="v",SUBSTITUTE(E2:G2,"v","")+0))
confirmed with CTRL+SHIFT+ENTER

How to add numbers in Excel in the same row and separate them by 'suffix'?

I have a list with more than 700 entries (see the picture below).
In row 'B' there are some numbers that have suffix "KM", "KN" or "E".
Is there some formula(or any solution) that can add these numbers but in the same time to separate these 3 suffixes(not to add them together, but to separate "KM", "KN" and "E"), so the solution can be something like:
1. 345 KM
2. 220 KN
3. 560 E
The below formulae should be able to split the numbers and the suffixes found in column B:
=LEFT(B1, 0, FIND(" ", B1))
=LEFT(B1, FIND(" ", B1)+1, 9999)
If you wanted to avoid VBA, you could use DSUM. I've never actually used it, but I know it can be useful for this type of thing. Hopefully that points you in the right direction!
Use Data \ Text to Columns to split your column based on the space character, then pivot your data and use the Unit (KM, KN, E) as a row field and the number as a data field.
With data in B1 , in C1 enter:
=--MID(B1,1,FIND(" ",B1)-1)
and copy down. In D1 enter:
=MID(B1,FIND(" ",B1)+1,999)
and copy down
Finally to get the sums, use formulas like:
=SUMPRODUCT((C:C)*(D:D="KM"))
It sounds like you want to add each type of suffix together.
Simplest way is to separate the numbers into its own column.
You can enter =NUMBERVALUE(LEFT(B1,SEARCH(" ",B1))) in cell C1 and copy down for each row to accomplish this. Then use a SUMIF function to get the results.
KM: =SUMIF(B1:B999,"=*KM",C1:C999)
KN: =SUMIF(B1:B999,"=*KN",C1:C999)
E: =SUMIF(B1:B999,"=*E",C1:C999)

Conditional Min and Max in Excel 2010

I would like to find Min and Max of Quantity (Column 2) based on Type (coloumn 1), is it possible to have this done?
I have tried this but the result was unexpected
Similar question
Assuming your data above is in A2:B13, this works:
=MAX(IF(A2:A13="A",1,0)*(B2:B13))
=MAX(IF(A2:A13="B",1,0)*(B2:B13))
=MAX(IF(A2:A13="C",1,0)*(B2:B13))
You have to press ctrl+shft+Enter when you enter the formula into a cell. This finds all rows with the A, B, or C, and multiplies 1 with the value next to it if the letter matches your formula, and 0 if it doesn't match. Then you take the MAX() of the values.
<<< Edit >>>
As #GSerg suggested, you can also do it with these formulas, if you press ctrl+shft+Enter when entering them into each cell:
=MAX(IF(A:A="A",B:B))
=MAX(IF(A:A="B",B:B))
=MAX(IF(A:A="C",B:B))
A much more elegant way of doing it!
Anything other than a PivotTable (as suggested by #andy holaday) seems sheer masochism (unless for a very good but presumably very peculiar reason):
Note that for illustration I doubled the OP's data quantities for B and these again for C.
This works without ctrl+shift+enter, but your table should be sorted by a TYPE column.
Let's assume that your table is placed in B3:C15, then in A4 put
=IF(B4=B3;A3;A3+1)
in E4 - "1", in E5 - "2" , in E6 - "3", in F4 put:
=MAX(INDIRECT("C" & MATCH(E4;$A$1:$A$17;0) & ":C" & MATCH(E4;$A$1:$A$17;1) ))
and copy it to F5 and F6
in G4 put:
=MIN(INDIRECT("C" & MATCH(E4;$A$1:$A$17;0) & ":C" & MATCH(E4;$A$1:$A$17;1) ))
and copy it to G5 and G6
MATCH function handles strings incorrectly, so I had to number TYPEs, you can use VLOOKUP to change numbers in column E to a strings
In my table I used this solution to find strings with maximum values this way:
A rather sneaky but simple way to do it is
1. create a new column that concatenates both Type and Qty and Call it "TypeQty" or whatever you'd like
2. Sort (Ascending) the new table ie Type,Qty and TypeQty all together but sort on the TypeQty column.
3. apply a formulat that checks if the type in the row above is the same as the current row. if not then mark that row because its the last of the current type.
you will end up with the "mark" only the max rows for each type.
See screenshots
#JamesL's solution always resulted in zero for me when attempting
=MIN(IF(A2:A13="A",1,0)*(B2:B13))
If I set it up with an arbitrarily large number for the false result, then it worked
=MIN(IF(A2:A13="A",1,99999)*(B2:B13))
However, #GSerg's elegant solution also works for the min:
=MIN(IF(A:A="A",B:B))
I would suggest to use =large(if(...=...;...);k) to solve that problem.

Resources