I am looking to sum values in a row based on a horizontal month range and vertical name range.
Here is what I am trying to achieve:
**Name** 1 2 3 4 5
Michael $24,000 $36,000 $24,567 $45,000 $36,900
Jerry $27,000 $39,090 $55,567 $85,000 $39,900
Sandra $24,000 $36,000 $24,567 $45,000 $36,900
Michelle $24,000 $36,000 $24,567 $45,000 $36,900
I want to be able to sum based on the month range.
For example, If I want to know what the value is for Sandra in months 3-5 ($24,567 + $45,000 + $36,900)
So everytime I play around with the range it should give me the sum of those values.
I tried an index match match function but I could only do it for a specific month not a range.
This was the formula I used :
=INDEX(Quota!$A$3:$P$29,MATCH('Summary by Rep'!A7,Quota!$A$3:$A$29,0),MATCH('Summary by Rep'!B4,Quota!$A$3:$P$3,0))
Any help would be greatly appreciated!
Use this array formula:
=SUM(INDEX(B2:F5,MATCH(I4,A2:A5,0),N(IF({1},ROW(INDIRECT(I2&":"&I3))))))
confirm with Ctrl-Shift-Enter instead Enter when exiting edit mode:
Or this that can be entered normally:
=SUMPRODUCT(B2:F5*(A2:A5=I4)*(B1:F1>=I2)*(B1:F1<=I3))
Just building on Scott Craner's answers with another solution that does not involve array or array like formulas.
The INDEX function actually returns a cell address instead of a value. Therefore you can use index once to define your starting cell of the range to sum, and then again to define the end cell of the range.
=SUM(INDEX():INDEX())
So based on the above formula you just need to figure out how your are going determine the start cell and then repeat the process for your end cell. I did it with the MATCH function. and used the following formula:
=SUM(INDEX($B$2:$F$5,MATCH($H4,$A$2:$A$5,0),MATCH($I4,$B$1:$F$1,0)):INDEX($B$2:$F$5,MATCH($H4,$A$2:$A$5,0),MATCH($J4,$B$1:$F$1,0)))
One small caveat that I have not tested, is that your name list and month list will may need to be sorted in ascending order.
Related
I've been struggling with this for hours now, and I just can't figure out how to add a second criteria to my formula.
I have this table:
device # date plan used
5 12/2/2017 A
8 12/3/2017 A
9 12/4/2017 B
56 12/2/2017 B
588 12/5/2017 C
56 12/2/2017 C
I am trying to get the number of unique devices, that are on plan A and have the date 12/2/2017. Here is the formula I have now.
=SUM(IF(FREQUENCY(IF(D2:D116005=G2,B2:B116005),IF(D2:D116005=G2,B2:B116005))>0,1))
I have successfully counted the unique devices with the criteria of being on 12/2/2017, but I just cannot figure out how to add additional criteria (i.e. on plan A). The G2 cell is where I am storing the date 12/2/2017 for comparison.
I have tried using IF(AND(.. but I can't seem to get it to work.
Could someone help me with this? Let me know if more information is needed.
Thank you,
Staci
You can use multiplication to return a 1 (equivalent to TRUE) if both match:
IF((Table1[date]=TargetDate)*(Table1[plan_used]=TargetPlan),Table1[device_'#],"")
Putting it all together:
=SUM(IF(FREQUENCY(IF((Table1[date]=TargetDate)*(Table1[plan_used]=TargetPlan),Table1[device_'#],""),IF((Table1[date]=TargetDate)*(Table1[plan_used]=TargetPlan),Table1[device_'#],""))>0,1))
Remember this is an array formula so must be confirmed by holding down ctrl + shift while hitting enter
I used structured references and named cells, but you should be able to transfer to your cell references.
in column D, starting in cell D2, put this formula:
=if(and(B2=date(2017,12,2),c2="A",countif($A$2:A2,A2)=1),1,0)
then just sum that column to get your answer.
Assuming plans in column F try this revised array formula:
=SUM(IF(FREQUENCY(IF(D2:D116005=G2,IF(F2:F116005="A",B2:B116005)),B2:B116005),1))
confirmed with CTRL+SHIFT+ENTER
Notice that it's not necessary to repeat the IF functions I the "bins array" argument of the FREQUENCY function
No formulas required: Simply whip up a PivotTable of the data, put Device and Date in the Rows field, and drag Plan to the Values area, which will automatically be given the COUNT treatment by the PivotTable because it's a text field.
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))
I've tried using SUMIF to obtain my results but it doesn't work properly.
I have a row of dates (XX/XX/XXXX format) and I would like to check this row for the current date.
If the row contains the current date, then I would like to sum the total of that column and row 5-20.
For example - today is 10/13/2016. I would like to search for TODAY() in a certain row (Row 1 for example), and if TODAY() is found, then total this column from row 1 down to row 3.
--A-- --B--
10/13/2016 10/14/16
1 50 10
2 10 4
3 5 6
The result should be 65 only IF the date matches TODAY().
I've also checked on giving the column letter based on the date but with no luck.
Any tips are appeciated! Thank you.
I think you can achieve this with a simple IF and a SUM
i.e. in your example above if you want the result to appear on the bottom row you can just use:
=if(B2=today(), sum(B3:B5), "")
This will display the sum at the bottom of the column for columns where the date = today and a blank in the other columns
You need to use the OFFSET function. You can find the documentation here: https://support.office.com/en-us/article/OFFSET-function-C8DE19AE-DD79-4B9B-A14E-B4D906D11B66
In your particular example the following formula will work:
=SUM(OFFSET(D2, 1, MATCH(B2, $D$2:$F$2, FALSE) - 1, 20))
You can see the formula working below. Assuming you know what the SUM formula is doing, I will explain what the OFFSET formula is doing:
First Parameter: Says start at cell D2
Second Parameter: This is how many row up/down do you want to do. In your case you need start at row below the date so '1' it is.
Third Parameter: This is how many columns to the right do you want to
go. Well the number of columns you want to go is based upon where
your date is. So this uses the match formula to figure out how far
to the right to go.
Fourth Parameter: This is how many row do you want to include. I just picked 20 to include the 20 rows below the selected cell.
You obviously need to modify the parameters a little bit to fit your exact data shape.
So I'll give it a shot:
{=SUM(HLOOKUP(TODAY(),Table_With_Dates_and_Three_Rows_Cell_Reference,{2,3,4}))}
NB: Don't type {} but put the formula inside it and then hit Ctrl+Shift+Enter to create what is called an array formula (it does array calculations element by element then submits the aggregating function value---in this case that is sum).
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))
I need to return a median of only a certain category on a spread sheet. Example Below
Airline 5
Auto 20
Auto 3
Bike 12
Airline 12
Airline 39
ect.
How can I write a formula to only return a median value of the Airline Categories. Similar to Average if, only for median. I cannot re-arrange the values. Thank you!
Assuming your categories are in cells A1:A6 and the corresponding values are in B1:B6, you might try typing the formula =MEDIAN(IF($A$1:$A$6="Airline",$B$1:$B$6,"")) in another cell and then pressing CTRL+SHIFT+ENTER.
Using CTRL+SHIFT+ENTER tells Excel to treat the formula as an "array formula". In this example, that means that the IF statement returns an array of 6 values (one of each of the cells in the range $A$1:$A$6) instead of a single value. The MEDIAN function then returns the median of these values. See http://www.cpearson.com/excel/arrayformulas.aspx for a similar example using AVERAGE instead of MEDIAN.
Make a third column that has values like:
=IF(A1="Airline",B1)
=IF(A2="Airline",B2)
etc
Then just perform a median on the new column.
Expanding on Brian Camire's Answer:
Using =MEDIAN(IF($A$1:$A$6="Airline",$B$1:$B$6,"")) with CTRL+SHIFT+ENTER will include blank cells in the calculation. Blank cells will be evaluated as 0 which results in a lower median value. The same is true if using the average funtion. If you don't want to include blank cells in the calculation, use a nested if statement like so:
=MEDIAN(IF($A$1:$A$6="Airline",IF($B$1:$B$6<>"",$B$1:$B$6)))
Don't forget to press CTRL+SHIFT+ENTER to treat the formula as an "array formula".
one solution could be to find a way of pulling the numbers from the string and placing them in a column of just numbers the using the =MEDIAN() function giving the new number column as the range