Good day, I have finally decided to ask for help. I have 1 workbook, multiple worksheets. The formula gives me #Value! which I am understanding that it has a wrong datatype. I am simply wanting look at a range within 1 column of dates, then add a column of numbers in 2 separate columns and divide those 2 columns and multiply by 30. It amounts to this. SUM(D31/C31)*30. This small formula works great when just using the numbers. I am taking total hours divided by amount of production multiplied by 30 dollars per hour. Obviously I will do this for each month of the year.
The 2 sheets are labeled as follows. This formula below resides on sheet "Monthly". It is referencing sheet "Overall Cost". I am hoping I have given you enough information that perhaps you might have the time to assist me. Note: I have the range pretty long because this is supposed to work for the whole year so I made it 10,000 rows deep.
Formula:
=SUMPRODUCT(('Overall Cost'!$B$3:$B$10000<=DATE(2015,9,30))*('Overall Cost'!$B$3:$B$10000>=DATE(2015,9,1)),SUM(('Overall Cost'!$D$3:$D$10000)/SUM('Overall Cost'!$C$3:$C$10000))*30)
Sample data:
"B" "C" "D"
SQ FT Hours
Date OH OH
Wednesday 8/10/15 3427 232
Thursday 8/11/15 5536 232
Friday 8/12/15 2364 232
Monday 8/1/15 6408 232
Tuesday 9/4/15 2499 232
Wednesday 9/5/15 870 232
You cannot use a SUM function within a SUMPRODUCT function like that. The SUMPRODUCT is trying to process each row by row and the SUM is totalling all of the rows into a single figure.
You are also going to get a number of #DIV/0! errors due to SUMPRODUCT's strong calculation mode. Your extra rows ranging down to 10000 can be truncated to the extent of the dates in column B. Since they are the criteria, it stands to reason that no numbers in column C and D would be significant in rows beyond the last date.
=SUMPRODUCT(('Overall Cost'!B$3:INDEX('Overall Cost'!B:B, MATCH(1E+99, 'Overall Cost'!B:B ))<DATE(2015, 10, 1))*
('Overall Cost'!B$3:INDEX('Overall Cost'!B:B, MATCH(1E+99, 'Overall Cost'!B:B ))>=DATE(2015, 9, 1)),
'Overall Cost'!$D$3:INDEX('Overall Cost'!D:D, MATCH(1E+99,'Overall Cost'!B:B)),
30/'Overall Cost'!$C$3:INDEX('Overall Cost'!C:C, MATCH(1E+99,'Overall Cost'!B:B )))
I've also adjust your maths hierarchy a bit. Multiplying the division of columns C and D was the same as multiplying column D by the fraction created by 30 over column C.
Providing you have no zero values in column C you should be alright. If you do then an IFERROR function or additional criteria may have to be brought in. This formula also limits calculation only to exactly what is needed with no blank 'safety-zone' of blank cells.
If yo are still receiving #DIV/0! errors then there must be blank cells or cells with 0 in column C. A #DIV/0! error is literally that; you are trying to divide a number by zero.
This can be solved with the IFERROR function but an extra layer of processing is required so you need to use Ctrl+Shift+Enter↵ to finalize the following formula.
=SUMPRODUCT((oc!B$3:INDEX(oc!B:B, MATCH(1E+99, oc!B:B ))<DATE(2015, 10, 1))*
(oc!B$3:INDEX(oc!B:B, MATCH(1E+99, oc!B:B ))>=DATE(2015, 9, 1)),
oc!$D$3:INDEX(oc!D:D, MATCH(1E+99,oc!B:B)),
IFERROR(30/oc!$C$3:INDEX(oc!C:C, MATCH(1E+99,oc!B:B )), 0))
This can be mimicked with a non-CSE formula by forcing the numerator to zero and the denominator to one when encountering a #DIV/0! situation.
=SUMPRODUCT((oc!B$3:INDEX(oc!B:B, MATCH(1E+99, oc!B:B ))<DATE(2015, 10, 1))*
(oc!B$3:INDEX(oc!B:B, MATCH(1E+99, oc!B:B ))>=DATE(2015, 9, 1))*
(oc!$C$3:INDEX(oc!C:C, MATCH(1E+99,oc!B:B ))<>0),
oc!$D$3:INDEX(oc!D:D, MATCH(1E+99,oc!B:B)),
30/(oc!$C$3:INDEX(oc!C:C, MATCH(1E+99,oc!B:B ))+
(oc!$C$3:INDEX(oc!C:C, MATCH(1E+99,oc!B:B ))=0)))
Related
I have an NFL spreadsheet where each row represents a specific team, and every 5 columns represents weekly information about the team (Column A is the team, Columns B-F are stats for week 1, G-K are stats for week 2, etc.). I am trying to perform different calculations on information from the same stat for each week (I.E. sum of columns B,G...). One column includes the teams margin of victory for each week. In order to calculate the teams Win/Loss record, I attempted to use a COUNTIF() function, counting each Margin of Victory column for each week - count a Win for each week where the MOV is greater than 0, Loss for less than zero.
=COUNTIF((Weeks!E3,Weeks!J3,Weeks!O3,Weeks!T3,Weeks!Y3,Weeks!AD3,Weeks!AI3,Weeks!AN3,Weeks!AS3,Weeks!AX3,Weeks!BC3,Weeks!BH3,Weeks!BM3,Weeks!BR3,Weeks!BW3,Weeks!CB3,Weeks!CG3),>0)
The result is a formula parse error, because I've entered too many arguments for the COUNTIF() function (although my assumption was adding parentheses around the data would make it one argument). The desired outcome, reference the picture for example, would be on another sheet to produce 1 loss and 1 tie (in separate cells) for Arizona (Week 1 margin = 0, week 2 margin = -6), and then replicate this over the course of 17 weeks as implemented in the formula.
Maybe some of these formula's:
For positive results:
=SUMPRODUCT((MOD(COLUMN(A3:CG3),5)=0)*(A3:CG3>0))
Or:
=SUM(INDEX((MOD(COLUMN(A3:CG3),5)=0)*(A3:CG3>0),))
For draws:
=SUMPRODUCT((MOD(COLUMN(A3:CG3),5)=0)*(A3:CG3=0))
Or:
=SUM(INDEX((MOD(COLUMN(A3:CG3),5)=0)*(A3:CG3=0),))
For negative results:
=SUMPRODUCT((MOD(COLUMN(A3:CG3),5)=0)*(A3:CG3<0))
Or:
=SUM(INDEX((MOD(COLUMN(A3:CG3),5)=0)*(A3:CG3<0),))
Change A3:CG3 to whichever range it actually goes to.
Instead of making a large countif, you can sum all of the individual countif functions.
=SUM(COUNTIF(Weeks!E3,">0"),COUNTIF(Weeks!J3,">0")...
So on and so forth. Since each countif function will return either a 0 or 1, summing all of those together should hopefully work. It might be a little annoying but this is how I've made formulas like that work. Let me know if this works for you.
I need a little help, I have an Excel book with a long list of customers and in the adjacent cell is ether a 1 or 0 depending if the customer has ordered in the past month.
How can I split this list into 2 lists on another page one been ordered in the past month and the other not ordered,
Im unable to use Macros due to security levels on the PC.
Thanks
Try,
'for ones
=INDEX(A:A, AGGREGATE(15, 7, ROW(B$2:INDEX(B:B, MATCH(1E+99, B:B)))/(B$2:INDEX(B:B, MATCH(1E+99, B:B))=1), ROW(1:1)))
'for zeroes
=INDEX(A:A, AGGREGATE(15, 7, ROW(B$2:INDEX(B:B, MATCH(1E+99, B:B)))/(B$2:INDEX(B:B, MATCH(1E+99, B:B))=0), ROW(1:1)))
Of course, you will have to modify to suit the different worksheet.
See the image below. Using array formulas (Ctrl+Shift+Enter) I entered this into D2:D8:
=IFERROR(INDEX(A2:A8,SMALL(IF(B2:B8,ROW(A2:A8)-ROW(A1)),ROW(A2:A8)-ROW(A1))),"")
and this into E2:E8:
=IFERROR(INDEX(A2:A8,SMALL(IF(1-B2:B8,ROW(A2:A8)-ROW(A1)),ROW(A2:A8)-ROW(A1))),"")
Explanation
This is how Excel will calculate the first formula:
=IFERROR(INDEX(A2:A8,SMALL(IF(B2:B8,ROW(A2:A8)-ROW(A1)),ROW(A2:A8)-ROW(A1))),"")
=IFERROR(INDEX(A2:A8,SMALL(IF({1;0;1;0;0;0;1},{2;3;4;5;6;7;8}-1),{2;3;4;5;6;7;8}-1)),"")
=IFERROR(INDEX(A2:A8,SMALL(IF({1;0;1;0;0;0;1},{1;2;3;4;5;6;7}),{1;2;3;4;5;6;7})),"")
=IFERROR(INDEX(A2:A8,SMALL({1;FALSE;3;FALSE;FALSE;FALSE;7},{1;2;3;4;5;6;7})),"")
Since the second argument of SMALL is an array, it will find the 1st, 2nd, 3rd, etc. value, ignoring FALSE (it will return #NUM! for the 4th through 7th value).
=IFERROR(INDEX(A2:A8,{1;3;7;#NUM!;#NUM!;#NUM!;#NUM!}),"")
=IFERROR({"A";"C";"G";#NUM!;#NUM!;#NUM!;#NUM!},"")
={"A";"C";"G";"";"";"";""}
I would like to find the row at which running summed value has reached a specified amount and several criteria have been met (similar to sumifs).
I can't just add a cumulative row, as suggested here:
Count rows until the sum value of the rows is greater than a value
....because I have other criteria to meet in the data, and therefore can't have a running total.
In the following dummy example, I'd like to find the date at which the "Design" project has spent or exceeded $30,000
A late answer, but one that doesn't use a Helper Column.
By using Matrix Multiplication (MMULT) on a TRANSPOSEd array of whether the Row is larger than itself and the list itself, we can produce an array of the Running Total.
MMULT(--(TRANSPOSE(ROW(D2:D21))<=ROW(D2:D21)), D2:D21)
If we shrink this to just the first 3 rows, to demonstrate, then you are making this calculation:
[[--(2<=2)][--(3<=2)][--(4<=2] [[10,000]
[--(2<=3)][--(3<=3)][--(4<=3] ∙ [ 8,000]
[--(2<=4)][--(3<=4)][--(4<=4]] [ 6,000]]
Which gives us this:
[[1][0][0] [[10,000] [[10,000]
[1][1][0] ∙ [ 8,000] = [18,000]
[1][1][1]] [ 6,000]] [24,000]]
We can then compare that against the target value as a condition and divide by the result to eliminate values with #DIV0! errors, and use AGGREGATE to get the smallest non-error value
=AGGREGATE(15, 6, Row(D2:D21) / (MMULT(--(TRANSPOSE(ROW(D2:D21))<=ROW(D2:D21)), D2:D21)<30000), 1)
This will give us the first row where the Running Total is >= $30,000
make a cumulative row, only adding up if column B equals 'Design'
If you want to be able to do a vlookup, you should make an extra column that checks if amount exceeded 30k, and then output anything that will be your key for the vlookup.
Ok, for anyone who is interested, here is what I ended up doing. I created a separate table that had all of my possible weeks (10/17, 10/24, 10/31, etc.) in one column, and corresponding sequential numbers in the next column. I ended up with 54 in my actual project.
Then, I ended up having to insert one column into my dataset for the purposes of looking up that "Week No", for each "Week" in all rows. Then on my other sheet where I was solving, I had a cell be my decision variable for the week #. I had another be my target $. I created a formula that took my target amount minus the SUMIFS for all of my criteria (Project, Name, etc.) with the last criteria being that the week number had to be "<=" & (decision cell). I then used Solver to minimize the output by changing the target week with constraints that the target week had to be integer, >=1, <=54, and that the output had to be >=0. That got me to the week prior to where the funding went negative. I then had a cell lookup that week number +1 on my weeks table to find the week at which my target amount would be met.
Sorry, had to explain it that way, vs. the actual formula, as my actual formula has a lot of SUMIFS criteria and cell references that wouldn't make any sense here.
I have two different sheets with 300,000 data in Excel.
First sheet contains:
S2_Symbol Start_Pos End Position
STE 254857 267891
PRI 748578 758962
ILA 852741 963369
VIS 789456 796325
Second:
S1_Location
789460
852898
748678
My output should be like this:
S1_Location Symbol
789460 VIS
852898 ILA
748678 PRI
I have to find that S1_location falls in which S2_location and its corresponding Symbol. I have used INDEX formula in Excel but for each cell, I have to change the reference cell manually. I couldn't do it 300,000 data.
How can I do in an in Excel or should I use a script?
This solution assumes the following:
Start and End Positions for each S2 Symbol are unique (i.e. there is no intersection between the ranges allocated to each symbol)
Data in first sheet is located at A1:D17 (adjust ranges in formulas as needed)
Data in second sheet is locate at A1:B300010 (adjust ranges in formulas as needed)
The solution requires:
To add a working column in worksheet one. Enter this formula in D2 and copy till last record.
=ROWS($A$1:$A2)
Fig. 1
Then in second worksheet enter this formula at B2 and copy till last record.
=INDEX( Sheet1!$A$1:$A$17,
SUMIFS( Sheet1!$D$1:$D$17,
Sheet1!$B$1:$B$17, "<=" & $A2, Sheet1!$C$1:$C$17, ">=" & $A2 ) )
Fig. 2
It took aprox. less than 14 seconds to copy downwards and calculate the formulas in sheet 2.
As it can be seen in figures 1 and 2 none of the tables need to be sorted.
Assuming both sheets start in A1, and First sheet ColumnB is sorted ascending, in Second sheet B2 please try:
=INDEX(First!A:A,MATCH(A2,First!B:B))
copied down to suit. It relies on inexact matching.
Assuming we have a Sheet1 like this:
note, the Sheet1is sorted by Start_Pos, End_Pos in ascending order.
and a Sheet2 like this:
Then the formula in Sheet2!B2 downwards could be:
=INDEX(Sheet1!A:A,IF(MATCH(A2,Sheet1!B:B)>IFERROR(MATCH(A2-(10^-10),Sheet1!C:C),0),MATCH(A2,Sheet1!B:B),NA()))
See MATCH: https://support.office.com/en-us/article/MATCH-function-e8dffd45-c762-47d6-bf89-533f4a37673a
The idea is: MATCH without exact matching (without parameter match_type) gets the row of the largest value which is smaller or equal the search value. So in the Start_Pos column it will get the row from which we can get the S2_Symbol. But from the End_Pos column it should get one row beforehand if the value is not outside the given ranges.
There is only one exception. If the value is exact the value in the End_Pos column, then it will return the same row as in the Start_Pos column. Considering this exception, we can search in the End_Pos column with a little bit smaller value. Thanks to Tom Sharpe for his comment.
The formula in Sheet2!D2 downwards is:
{=INDEX(Sheet1!A:A,MIN(IF($A2>=Sheet1!$B$2:$B$300000,IF($A2<=Sheet1!$C$2:$C$300000,ROW(Sheet1!$A$2:$A$300000),2^20+1))))}
this is an array formula which is exactly formulated respecting the requirements. But this is very bad in performance for using in much many cells. But using this, the Sheet1 is not required to be sorted.
Benchmark test:
Have the following Sheet1:
Formulas:
A2:A300002: ="S"&(ROW(A1)-1)*10&"-"&(ROW(A1)-1)*10+7
B2:B300002: =(ROW(A1)-1)*10
C2:C300002: =B2+7
and the following Sheet2:
Formulas:
A2:A300002: =RANDBETWEEN(0,3000007)
B2:B300002: =INDEX(Sheet1!A:A,IF(MATCH(A2,Sheet1!B:B)>IFERROR(MATCH(A2-10^-9,Sheet1!C:C),0),MATCH(A2,Sheet1!B:B),NA()))
Note the -10^-9 instead of -10^-10 in previous version. This is because we have only 16 digits precision. In previous version this was maximum 6 digits integer part and then 10 digits decimal part. Now it is maximum 7 digits integer part and then 9 digits decimal part.
Calculation after pressing F9 in Sheet2 takes ca. 2 s. (Excel 2007, Windows 7, 4 core processor).
I would have gone for something like this which gives you the first match if there is one:-
=INDEX(First!A:A,MATCH(1,(First!B:B<=A2)*(First!C:C>=A2),0))
assuming keys and start and end values are in a sheet called First and lookup values start in A2.
Array formula which must be entered with CtrlShiftEnter
In response to the question from #pnuts about how long it will take, I have set up a similar benchmark with 300,000 rows in each sheet and it has reached 1% after 90 minutes, so it should take about 150 hours to reach 100% or roughly one week. This is to be expected as the number of computations required is (rows in sheet 1) X (rows in sheet 2)
300,000 X 300,000
but in fact because the multiplication applies to complete columns, I believe it is more correctly
300,000 X 1,048,576
i.e. > 300 billion.
A practical version which gives good response for smaller ranges is as follows:-
I define three named ranges Range1, Range2 and Range3
=First!$A$1:INDEX(First!$A:$A,MATCH("ZZZ",First!$A:$A))
=First!$B$1:INDEX(First!$B:$B,MATCH(9.9E+307,First!$B:$B))
=First!$C$1:INDEX(First!$C:$C,MATCH(9.9E+307,First!$C:$C))
and the modified formula is
=INDEX(Range1,MATCH(1,(Range2<=A2)*(Range3>=A2),0))
I was thinking of deleting this answer, but would rather it stood as a counter-example.
My problem is the following...
I have a little aeroplane and I need to track the hours. I have to track the hours by sectors and not the total of the day (that's why sometimes I have 2 or 3 on the same day).
Now this is the problem... On column C I need to SUM the hours of the last 7 days. And any given 7 days, not just last week. To do it manually is quite easy... the problem is that I need a formula as my records are quite large...
Here with a small example (let's say that there was NO HOURS before 15/01/2009)...
COLUMN A-------COLUMN B-------COLUMN C
DATE--------------HOURS-------HOURS LAST 7 DAYS
15/01/2009-------01:00-------01:00
15/01/2009-------02:15-------03:15
16/01/2009-------01:15-------04:30
17/01/2009-------01:30-------06:00
18/01/2009-------01:30-------07:30
18/01/2009-------01:00-------08:30
18/01/2009-------02:00-------10:30
19/01/2009-------02:30-------13:00
19/01/2009-------03:00-------16:00
20/01/2009-------////////--------16:00
21/01/2009-------01:00-------17:00
22/01/2009-------01:30-------15:15
23/01/2009-------02:00-------16:00
I've been fighting for the last weeks trying to figure out a formula but no luck... any suggestions?
Thanks
Another solution that basically does much the same as the earlier offered solutions:
In C1, enter the following formula:
{=SUM(IF(($A$1:$A1>=($A1-6))*($A$1:$A1<=$A1), $B$1:$B1, 0))}
And then just drag the formula down.
If you're not familiar with array formulas, the {} outer brackets just indicate that the formula is an array formula. To get it to execute correctly, you need to copy the part inside the {} brackets into the formula bar, and then hit Ctrl+Shift+Enter to indicate that it's an array formula.
First thing is to get the begin date, which would be the following function:
=Now() - 7
If you renamed that cell to "WeekBegin", then you could use the following formula to calculate the total hours:
=SUMIF(A:A,">=" & WeekBegin,B:B)
Notice that I used column references; this was to both simplify the formula, but also allow you to add new data to the end of the range easily. You will need to take care that your WeekBegin cell is not in that column A or column B, otherwise you'll get a circular reference warning.
If you planned to have numeric data above or below your input range, you would need to explicitly call out the sum and criteria ranges as follows:
=SUMIF(A2:A14,">=" & WeekBegin,B2:B14)
Additionally, you may find that your result comes up initially as a decimal. That's Excel's date serial format, so you may need to format your result as time.
Hope that helps!
[Edit: On second pass, if you're looking to sum a range based on a from and to date (so any 7 days as you seem to imply in your post), look for the previous poster's note, i.e.:
=SUM(B:B) - SUMIF(A:A, "<="& BeginDate, B:B) - SUMIF(A:A, ">"& EndDate, B:B)
A more elegant solution is offered in Excel 2007 using the SumIFS() function:
=SUMIFS(B:B, A:A, ">=" & FromDate,A:A, "<" & ToDate)
Note that the arguments for SUMIFS are in a different order than the standard SUMIF.
Happy Summing!]
Here's the data in better format if someone wants to try:
15-Jan-2009 01:00
15-Jan-2009 02:15
16-Jan-2009 01:15
17-Jan-2009 01:30
18-Jan-2009 01:30
18-Jan-2009 01:10
18-Jan-2009 02:00
19-Jan-2009 02:30
19-Jan-2009 03:00
20-Jan-2009
21-Jan-2009 01:00
22-Jan-2009 01:30
23-Jan-2009 02:00
I got the function:
=SUM($B$1:$B$13)-SUMIF($A$1:$A$13, "<="& (A1- 7), $B$1:$B$13) - SUMIF($A$1:$A$13, ">"& (A1), $B$1:$B$13)
This was based on Sum of named ranges conditional to date?.
The idea is to first compute the total sum: SUM($B$1:$B$13)
then subtract any values that happened older than 7 days ago: SUMIF($A$1:$A$13, "<="& (A1- 7), $B$1:$B$13)
then subtract any values that happened in the future: SUMIF($A$1:$A$13, ">"& (A1), $B$1:$B$13)
The point is to use SUMIF function, which "adds the cells specified by a given criteria."