Sum up numeric lead part of strings - excel

Column1 Column2 Column3 Column4.
350 mac 360 jan
500 jan 200 mac
This is excel.. How to sum up in just one excel formula like you want a total for jan which is 860 and mac as well..
Thank you so much!

Please try this formula.
=SUM(IF(RIGHT(SumRng,3)=A$1,VALUE(LEFT(SumRng,LEN(SumRng)-4)),0))
SumRng is a named range containing all your items to be summed. In your example it may have been like A2:D2.
A1 contains the search text. In your example it's either "jan" or "mac". Note that it's not case sensitive. "Jan" and "Mac" will be included in the sum.
I tested the formula in Excel 365. However, in older versions of excel you may have to enter it as an array formula, confirming it with Ctl + Shift + Enter

I used an Excel table, and named it tbl.
If you have Excel O365, you can try:
=SUM(IF(H2=INDEX(tbl,SEQUENCE(ROWS(tbl)),SEQUENCE(,COLUMNS(tbl)-1,2,1)),INDEX(tbl,SEQUENCE(ROWS(tbl)),SEQUENCE(,COLUMNS(tbl)-1,1,1))))
The INDEX functions create two arrays, each one column less than the original table. When we see a match, we return the cell offset one to the left of the matched cell, giving you the totals you want.

Related

COUNTIFS and SUMPRRODUCT for unique text within a date range for all rows

I am trying to use COUNTIFS and SUMPRODUCT to count the number of unique text for a date within certain range for all rows.
For example, I would like to count the number of unique count for the items that are in February.
Date, Item Description, , Start, 2017-02-01
02/1/2017, abc, , End, 2017-03-01
03/2/2017, def
05/2/2017, abc
08/2/2017, def
01/3/2017, abc
05/3/2017, def
If I specify the range like this (i.e. from row 1 to 6), it does work and return 2.
=SUMPRODUCT((($A1:$A6>=$E1)*($A1:$A6<$E2))/COUNTIFS($B1:$B6, $B1:$B6, $A1:$A6, ">="&$E1, $A1:$A6, "<"&$E2))
However, if I specify the whole column it won't work and return 0.
=SUMPRODUCT((($A:$A>=$E1)*($A:$A<$E2))/COUNTIFS($B:$B, $B:$B, $A:$A, ">="&$E1, $A:$A, "<"&$E2))
Please suggest how can I fix this to do for all rows?
Probably more efficient to use an array formula with FREQUENCY, and that type of formula can cope with blank rows so you should just make the range large enough to cater for current data and possible future expansion, e.g. for data in rows 2 to 1000 you can use an array formula like this:
=SUM(IF(FREQUENCY(IF(A$2:A$1000>=E1,IF(A$2:A$1000<E2,MATCH(B$2:B$1000,B$2:B$1000,0))),ROW(B$2:B$1000)-ROW(B$2)+1),1))
confirm with CTRL+SHIFT+ENTER
You could use a dynamic named range e.g. Dates and enter this into the formula. It will then only evaluate for the required number of rows. Won't have the added luxury of barry houdini's answer which caters for blank cells in the range.
Ctrl + F3 will open the Name Manager and there you can click > New and enter Dates for the name and use a variation on the following formula for the Refers to:
=OFFSET(Sheet1!$A$2,0,0,COUNT(Sheet1!$A$2:$A$1048576),1)
The $A$1048576 is the last row in versions of Excel above 2003 and $A$65536 would be for before.
=SUMPRODUCT(((Dates>=$E1)*(Dates<$E2))/COUNTIFS(OFFSET(Dates,,1,,1), OFFSET(Dates,,1,,1), Dates, ">="&$E1, Dates, "<"&$E2))

Use a variable for columns in SUMPRODUCT and VLOOKUP formula

I'm trying to use this formula:
=SUMPRODUCT(VLOOKUP(B$4778,$D$4:$DC$4623,{4,5},0))
It works fine but I'd like to try to use a variable for the {4,5} portion of the formula (columns in the array to be summed) as the formula needs to change based on sheet inputs before this formula.
I have cells on the sheet that are to be used to set the initial and final columns to be searched (likely 10 columns, but the 10 columns would have to be selected from 90 some columns available).The columns are populations related to each age. So, if I need population of those aged 10 through 15, I'd need to sum up 5 columns. If 20-25, need to sum up 5 different columns.
I tried to use the Columns function but it didn't seem to work for me.
The columns are selected by users entering in cells the upper and lower limits of the search range and then I convert those values to the corresponding numerical column value.
So if they select 5 as lower and 10 as upper limit, I know I have to add 7 to get the correct data column on the data page (column 12) and likewise for upper (column 17).
The entire possible area to search is $D$4:$DC$4623. So, in the formula, if I wrote it out long way it would be:
=SUMPRODUCT(VLOOKUP(B$4778,$D$4:$DC$4623,{12,13,14,15,16,17},0))
I'd prefer to write it out using variables, something like this:
=SUMPRODUCT(VLOOKUP(B$4778,$D$4:$DC$4623,{L:U},0))
Where variable L would be 12 and variable U would be 17.
Can anyone suggest a way to write the formula?
use this array formula:
=SUM(VLOOKUP(B$4778,$D$4:$DC$4623,ROW(INDIRECT(D5 & ":" & E5)),FALSE))
Where D5 is the Lower and E5 would be the upper.
Being an array formula it must be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode. If done correctly then excel will put {} around the formula.
Or better yet use this non array formula:
=SUM(INDEX($D$4:$DC$4623,MATCH(B$4778,$D$4:$D$4623,0),D5):INDEX($D$4:$DC$4623,MATCH(B$4778,$D$4:$D$4623,0),E5))

Summing a Column in Excel 2010 based on multiple criteria

InExcel 2010, I need to sum one column if another column is equal to a month and another colums is equal to "N" I have part of the answer, I just need to add the second criteria and the normal Sumifs does not seem to work with this because of the month issue.
The month is part of a full date format. eg 12 January 2014
This is what I ahve so far and it works :)
=SUM(IF(MONTH('MBR Tracker'!$AJ:$AJ)=1,'MBR Tracker'!$AO:$AO,0))
Regards
Pat J
You can use SUMPRODUCT which will work without array entry:
=SUMPRODUCT('MBR Tracker'!$AO:$AO * (MONTH('MBR Tracker'!$AJ:$AJ) = 1) * ('MBR Tracker'!$AK:$AK = "N"))
Assuming that AK is the other column which should contain N.
You can use following array formula:
=SUM(IF((MONTH('MBR Tracker'!$AJ:$AJ)=1)*('MBR Tracker'!$AK:$AK="N"),'MBR Tracker'!$AO:$AO,0))
Note, since it's array formula, you need to press CTRL+SHIFT+ENTER to evaluate it.

In Excel 2007, how can I SUMIFS indices of multiple columns from a named range?

I am analysing library statistics relating to loans made by particular user categories. The loan data forms the named range LoansToApril2013. Excel 2007 is quite happy for me to use an index range as the sum range in a SUMIF:
=SUMIF(INDEX(LoansToApril2013,0,3),10,INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6))
Here 10 indicates a specific user category, and this sums loans made to that group from three columns. By "index range" I'm referring to the
INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6)
sum_range value.
However, if I switch to using a SUMIFS to add further criteria, Excel returns a #VALUE error if an index range is used. It will only accept a single index.
=SUMIFS(INDEX(LoansToApril2013,0,4),INDEX(LoansToApril2013,0,3),1,INDEX(LoansToApril2013,0,1),"PTFBL")
works fine
=SUMIFS(INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6),INDEX(LoansToApril2013,0,3),1,INDEX(LoansToApril2013,0,1),"PTFBL")
returns #value, and I'm not sure why.
Interestingly,
=SUMIFS(INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,4),INDEX(LoansToApril2013,0,3),1,INDEX(LoansToApril2013,0,1),"PTFBL")
is also accepted and returns the same as the first one with a single index.
I haven't been able to find any documentation or comments relating to this. Does anyone know if there is an alternative structure that would allow SUMIFS to conditionally sum index values from three columns? I'd rather not use three separate formulae and add them together, though it's possible.
The sumifs formula is modelled after an array formula and comparisons in the sumifs need to be the same size, the last one mimics a single column in the LoansToApril2013 array column 4:4 is column 4.
The second to bottom one is 3 columns wide and the comparison columns are 1 column wide causing the error.
sumifs can't do that, but sumproduct can
Example:
X 1 1 1
Y 2 2 2
Z 3 3 3
starting in A1
the formula =SUMPRODUCT((A1:A3="X")*B1:D3) gives the answer 3, and altering the value X in the formula to Y or Z changes the returned value to the appropriate sum of the lines.
Note that this will not work if you have text in the area - it will return #VALUE!
If you can't avoid the text, then you need an array formula. Using the same example, the formula would be =SUM(IF(A1:A3="X",B1:D3)), and to enter it as an array formula, you need to use CTRL+SHIFT+ENTER to enter the formula - you should notice that excel puts { } around the formula. It treats any text as zero, so it will successfully add up the numbers it finds even if you have text in one of the boxes (e.g. change one of the 1's in the example to be blah and the total will be 2 - the formula will add the two remaining 1s in the line)
The two answers above and a bit of searching allowed me to find a formula that worked. I'll put it here for posterity, because questions with no final outcome are a pain for future readers.
=SUMPRODUCT( (INDEX(LoansToApril2013,0,3)=C4) * (INDEX(LoansToApril2013,0,1)="PTFBL") * INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6))
This totals up values in columns 4-6 of the LoansToApril2013 range, where the value in column 3 equals the value in C4 (a.k.a. "the cell to the left of this one with the formula") AND the value in column 1 is "PTFBL".
Despite appearances, it isn't multiplying anything by anything else. I found an explanation on this page, but basically the asterisks are adding criteria to the function. Note that criteria are enclosed in their own brackets, while the range isn't.
If you want to use names ranges you need to use INDIRECT for the Index commands.
I used that formula to check for conditions in two columns, and then SUM the results in a table which has 12 columns for the months (the column is chosen by a helper cell which is 1 to 12 [L4]).
So you can do if:
Dept (1 column name range [C6]) = Sales [D6];
Region (1 column name range [C3]) = USA [D3];
SUM figures in the 12 column monthly named range table [E7] for that 1 single month [L4] for those people/products/line item
Just copy the formula across your report page which has columns 1-12 for the months and you get a monthly summary report with 2 conditions.
=SUMPRODUCT( (INDEX(INDIRECT($C$6),0,1)=$D$6) * (INDEX(INDIRECT($C$3),0,1)=$D$3) * INDEX(INDIRECT($E7),0,L$4))

Finding MAX value for a certain month

I have a problem that shouldn't be a problem but I'm unable to solve it.
My data looks like this:
2012-04-05 1280
2012-04-17 1340
2012-04-20 1510
2012-05-03 1670
2012-05-09 1880
What I want to do is to find the MAX value for april and for may.
So MAX for april should return 1510 and MAX for may should return 1880. Can this be done?
EDIT:
Maybe simplified it a bit too much, here is an example closer to what I really want to do:
2012-04-04 14 220
2012-04-11 453 863
2012-04-19 900 1310
2012-05-02 1400 1810
2012-05-15 1900 2250
These are milage from my cars trip computer. I would like to calculate how far I drove each month.
For april: 1310-14 = 1296
For may: 2250-1400 = 850
A simple array formula can do this. If your dates are formatted as dates in Excel, paste the following into a cell and press Ctrl+Shift+Enter:
=MAX(IF(MONTH($A$1:$A$5)=4,B1:B5))
Can this be expanded to also allow 0 to be filtered out? When you use the MIN instead of MAX and your data range has empty values this results into 0 to be reported as the lowest value.
A simple array formula can do this. If your dates are formatted as dates in Excel, paste the following into a cell and press Ctrl+Shift+Enter:
=MAX(IF(MONTH($A$1:$A$5)=4,B1:B5))
If your dates are formatted as text, paste the following into a cell and press Ctrl+Shift+Enter:
=MAX(IF(MID($A$8:$A$12,6,2)="04",$B$8:$B$12))
if you just need the answer once, filter by month and run a max function.
You could use a pivot table. Below, Amount is summarized by Max. I right-clicked on the date column, chose Group By and then selected both Year and Month. The picture obviously shows the source data, pivot table and two dialogs. In practice you'd put the pivot table on its own worksheet:
You can use this simple formula to get max of the month in a given range.
where J2 - J7 is my date range, use Max to get maximum of the dates in that range and use text to get the month.
=TEXT(MAX(J2:J7),"mmm")

Resources