I can't use a pivot table for this purpose, because this calculation takes place in a huge nested if formula.
Column A has unit
Column B has start date
Column C has end date
Column D:F has data.
Column E... is an attempt to bridge that data, so I can compare July to August.
EDITING QUESTION: I might as well throw it out here since everyone's doing it from scratch.
Okay, in this first picture, there's two dates, a start measurement, and a end measurement. I take end - start. Easy enough.
But then there's exceptions. Sometimes D:F
http://i.imgur.com/z9KhdmC.png
But my data isn't consistent. D:F may be full of zeroes. Sometimes July data is in August, but according to the bridge, that's not the case. I don't think July data will be past August 1st.
To explain that, this new picture is here.
http://i.imgur.com/QcR55s8.png
This is my current formula that I'm trying to figure out.
=IF(AND(B2>=DATE(2013,7,1),B2<=DATE(2013,8,1)),IF(G2<>0,IF(-need.to.prevent.duplicates.here-,F2-D2,0),V2),IF(AND(C2>=DATE(2013,7,1),C2<=DATE(2013,7,31)),IF(B2=DATE(2013,8,1),F2-E2,F2-D2),0))
Using the provided picture, try this formula in cell I32 (because that's where January should begin) and copied over and down:
=IF(TEXT($B32,"mmmm")=I$31,IF(TEXT($C32,"mmmm")=I$31,$G32,$E32-$D32),IF(TEXT($C32,"mmmm")=I$31,$F32-$E32,0))
Alternate (shortened) version to write the same thing:
=(TEXT($B32,"mmmm")=I$31)*($E32-$D32)+(TEXT($C32,"mmmm")=I$31)*($F32-$E32)
[EDIT]: I am including an example workbook here
You have not mentioned what you would like if the months are not both August, so in the following formula (in Row1 and copied down to suit) that scenario results in FALSE:
=IF(AND(MONTH(B1)=8,MONTH(C1)=8),IF(ISBLANK(E1),"OTHER",E1))
However when both are August this should meet your requirements, subject to "OTHER" being a place holder for you alternative formula.
Edit:
I think the above meets "I'd like a formula where if B and C has August. If so, please look for data in E. If data is not in E, do another formula." but if you want to test the presence of E data across all instances of a 'unit` then this:
=IF(AND(MONTH(B6)=8,MONTH(C6)=8),IF(COUNTIFS(A:A,A6,E:E,"<>"&""),"OTHER",E6))
I think I found my solution. My end result is this.
=IF(AND(B2>=DATE(2013,7,1),B2<=DATE(2013,8,1)),IF(G2<>0,IF(E2<>"",E2-D2,IF(P2=G2,0,F2-D2)),V2),IF(AND(C2>=DATE(2013,7,1),C2<=DATE(2013,7,31)),IF(N2>G2,V2-N2,G2-N2),0))
What I did was compare August to G2 (the total) to eliminate the duplicates. If August completely resembled it, then the formula would turn July to 0.
I'm also worked a little bit on the June data side.
Related
After years of using this community, I have a question that I can't find an answer to. I hope you all can help!
I am trying to get a count of the number of "Grounded" items that each individual is overdue for. My screenshot (Count Tracker) shows a very condensed version of what I'm working with. Columns A-C is my large (15,000 rows) data field that is imported from an external source. In columns G-H I have listed each possible task (about 100 rows) and the type (Grounded and Non-Grounding plus many others). Column F is where I am trying to get the count.
My formula in F9 currently uses COUNTIFS to get a count of the instances in the large array that equal E9 ("Smith" in this case) and where the due date in the large array is less than or equal to the current date in F8. What I can't figure out is how to also add to count the Tasks in the large array where the task type in Column H equals "Grounded". I tried VLOOKUP, but it seems it doesn't like it and tells me there is a problem with the formula. It doesn't work, but here's the general idea of what I'm after:
=COUNTIFS($A$2:$A$7,$E9,$C$2:$C$7,"<="&$F$8,VLOOKUP($B$2:$B$7,$G$2:$H$4,2,FALSE),"=Grounded")
With how the data is currently presented, Smith should have a count of 1 and Jones should have a count of 0. I have a feeling that this is more simple than I'm making it to be, but I can't figure it out. I am using Excel 2016.
Hopefully I explained the problem well enough. Thank you for your assistance.
With Excel 2016 I'd say MMULT() is a good alternative here:
CSE-Formula in F9:
=SUM((A$2:A$7=E9)*(MMULT((TRANSPOSE(G$2:G$4)=B$2:B$7)*(TRANSPOSE(H$2:H$4)="Grounding"),ROW(G$2:G$4)^0))*(C$2:C$7<=F$8))
You could add a fourth column that stores whether that Task is Grounded
The formula for D2 would then be:
=INDEX($H$2:$H$4,MATCH(B2,$G$2:$G$4,0))
Modify your CountIfs formula to use this new column as a criteria
=COUNTIFS($A$2:$A$7,$E9,$C$2:$C$7,"<="&$F$8,$D$2:$D$7, "Grounded")
Try this Sumproduct+Vlookup formula without helper solution, and can work for your Excel 2016
In F9, formula copied down :
=SUMPRODUCT((A$2:A$7=E9)*(VLOOKUP(T(IF({1},$B$2:$B$7)),G$2:H$4,2,0)="Grounded")*($C$2:$C$7<=$F$8))
I am using this formula for SUMIF which is working fine, but I need to add another criteria which is the DATE. I only want the jobs to sum total if the date is the same in column A. How do I accomplish this? When I use SUMIFS I get an error "too few arguments".
=SUMIF($B$2:$B$786,I2,$F$2:$F$786)
Setting the Stage
When making my initial response, I didn't notice that the OP's sample data included two separate data ranges. There is the main "table" with columns including DATETIME, PRODUCT and AVG CYCLE MINUTES. These are the data to be summed across. However, the sums are not to appear against these rows, but against the rows in the second "table" which has the column REFERENCE LIST. REFERENCE LIST matches with the PRODUCT column in the first table and so provides one of the criteria for the SUMIF(S). The second criteria was to be DATE. However, since the second table doesn't include a date column it isn't obvious where this should come from.
In discussion with the OP, we realised that we wanted a the total (or, as it turned out, average) of "AVG CYCLE MINUTES" for each combination of DATETIME and PRODUCT. I walked the OP through the process of creating a PivotTable to do this.
Options
If we want to achieve the same or similar by means of SUMIF or SUMIFS, we need to make a decision about the DATE criteria. Either (a) the second table needs to include dates as well as PRODUCTs, or (b) we need to find a way to pick the date we're interested in.
Sum for Every Combination of DATE and PRODUCT
For option (a), an answer similar to my original one would work:
=SUMIFS(F:F,B:B,I2,A:A,J2)
where column J is the new column of dates. The full list of date/product combinations could have been swiftly produced by copying the relevant columns of the main data to elsewhere and using Excel's "remove duplicates" functionality.
Sum for single DATE per PRODUCT
For option (b), if you wanted to sum up all the data relating to "today", that could be done using:
=SUMIFS(F:F, B:B, I2, A:A, today())
(with credit to #JNevill).
What else might we want? Perhaps the most recent date the PRODUCT appears against? Or the earliest? If you have EXCEL 2016 (or better) ...
=SUMIFS(F:F, B:B, I2, A:A, MAXIFS(A:A,B:B,I2))
This would give the total minutes for the relevant PRODUCT on the latest date recorded for that PRODUCT. For the earliest date replace MAXIFS with MINIFS.
Alternatively, if the data is sorted so that the date you want will be the first to appear against any given PRODUCT you can use:
=SUMIFS(F:F, B:B, I2, A:A, INDEX(A:A,MATCH(I2,I:I,0)))
Miscellanea
I'd normally use VLOOKUP rather than INDEX/MATCH (a habit I've yet to acquire), but in the current data structure the columns are in the wrong order for that.
Since further discussion revealed that the OP actually wanted averages not totals, it's worth noting the existence of AVERAGEIFS.
NOTE: in my original answer (below), I reference the exact ranges rather than entire columns. There may be some marginal performance loss doing things as above, but I've never noticed. Though you need to be sure there are no extra data beneath the stuff you're interested in. On the other hand, there are definite benefits, it's easier to enter the formula and it will not need amending for larger (or smaller) data sets. (Thanks for reminding me of this #Jeeped)
NOTE 2: Since there is there is nothing you can do with SUMIF that can't also be done with SUMIFS, there is no harm in using the latter even when the former would suffice. That way you only have one function to remember and it's the most useful one. (Another good idea from #Jeeped)
Original Answer
As others have said, I think you want SUMIFS. Here the sum_range comes to the front, and you follow that with pairs of "criteria range"s and "criteria" like this:
=SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)
In your case, I think that means you want:
=SUMIFS($F$2:$F$786,$B$2:$B$786,I2,$A$2:$A$786,A2)
When I wrote this, the relevant Microsoft Support page was here
I was hoping someone might be able to point me in the right direction, I'm trying to automate a section of a spread sheet which shows a persons planned hours of work against the hours they actually did. The data is sourced from a worksheet which is broken down into months and departments.
Is there a way to get the reference table on the main dashboard to vlookup/index a certain column dependent on the computers date?
I.E. for May it will look in the planned and actual hours column for may and then in June it will search the June column for the same data.
Normally I would post some code but I'm not even sure where to begin on this one.
You mention VLOOKUP in you question.
To use this in VBA use, WorksheetFunction.Vlookup(), but it seems you could avoid VBA altogether if you wanted. Here are some formulas of interest:
If you want to search months by the current date, you can use this kind of vlookup (or MATCH() or HLOOKUP() if these are columns as you indicate)
=VLOOKUP(TEXT(TODAY(),"mmmm"),Range,1,FALSE)
Use "mmm" if you use 3-letter months
If months are in static column number can be taken from using the MONTH() function.
=MONTH(TODAY())
"index a certain column dependent on the computers date?"
=TODAY() gets computer's date.
I would tend to use MATCH() to get the months column (in this example I've assumed months are in row 1)
=MATCH(TEXT(TODAY(),"mmmm"),1:1,0)
You can then use INDIRECT() to match a specific month column and department row (if in a 2D format), or SUMIFS() with INDIRECT() if you want to sum hours.
As in:
=INDIRECT("'Sheet'!R" & MATCH("department_name",A:A,0) & "C" & MONTH(TODAY()), FALSE)
Thank you for all the help in regards to this problem, unfortunatly I could not quite get my head round the suggestions which have been put forward, though I have been able to solve this problem (although it is a messy solution)
=IF($F$95="March",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,2,FALSE),
IF($F$95="April",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,3,FALSE),
IF($F$95="May",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,4,FALSE),
IF($F$95="June",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,5,FALSE),
IF($F$95="July",VLOOKUP(D97,'Planned Hours'!$A$1:K37,6,FALSE),
IF($F$95="August",VLOOKUP(D97,'Planned Hours'!$A$1:K37,7,FALSE),
IF($F$95="September",VLOOKUP(D97,'Planned Hours'!$A$1:K37,8,FALSE),
IF($F$95="October",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,9,FALSE),
IF($F$95="November",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,10,FALSE),
IF($F$95="December",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,11,FALSE)))))))))))
But it works. Again thanks to all that lent a hand.
--EDIT--
By the way this is not in VBA in the end.
i have multiple columns in my excel spreadsheet (DOLLAR, Date, Year), i am trying to get the values in column DOLLAR, if the DATE is greater than 01 Jan 2014, and the YEAR is 2014.
I tried sumproduct, countifs, if, match and even combinations of them but i cant seem to get the value of DOLLAR based on the criteria. how would i go about doing this? i am still a bit new to this so i don't quite know all the functions yet.
i have something like this right now, also all the DOLLAR value that meets the criteria will all be summed up.
=IF('CDT DWGS-2014'!F:F=2014,IF('CDT DWGS-2014'!Q:Q>DATEVALUE("01-Jan-2014"),"GET DOLLAR VALUE",0),0)
Thank you
Ok, given your extra comments, I also tried to make it a bit more robust for you, so suppose, in your sheet you had:
A1 = Start Date
B1 = End Date
And in your CDT DWGS-2014 sheet, the Dollar amounts were in column A and the dates were in column B, You could use the following formula:
=SUMIFS('CDT DWGS-2014'!A:A,'CDT DWGS-2014'!B:B,">="&A1,'CDT DWGS-2014'!B:B,"<="&B1)
This could be made simpler, but this should do the trick.
Hope this helps!!
Use this formula. Column A, B and C are for DOLLAR, Date and Year respectively.
=SUMPRODUCT(A2:A11,--(B2:B11>DATE(2014,1,1)),--(C2:C11=2014))
New to VBA, please help. My apologies. I have not done a good job of making myself clear. Let me try one more time.
My sales reps enter every call into a call sheet. They call on 50-60 people a week; some they will see more than once a week, some only a couple of times a year. On this call sheet are 4 columns; date of call, customer, numerical date, and days since last call. This sheet may have hundreds of rows, many are duplicate customers called on a different date.
I have written code that will eliminate duplicates as needed (works fine). New calls are added using NextRow=_ (also works fine). $C$2 is set at TODAY().
Formula in column C is $C10=$A10(Column C is formatted to number). Column D is number of days since last call; $C$2-$C10 etc. Simple and works fine.
Issue is that say I have 50 rows (all different customers) sorted ascending and a new customer is added, key being new. I need the formulas in C and D to drop down one row automatically when the new customer is added. I can drag the formulas down a head of time and everything will work until I sort, then my data is a the bottom of my sort because all rows in column A without a date will produce a 0 in both C and D. My finished product should be a range of different customers (no duplicates); with the customer that has not been called on the longest at the top.
I hope this is a better explanation. Can I write code to ignore the 0's?
I am going to go a little out on a limb here and say maybe your formulas need refactoring...
For instance. If the aim is to calculate the days since the last call was made to a customer, a simple formula such as this would work
=(max(C:C)-Today())
This gets the largest value in column C and subtracts today from it.
If you want to get the value in column D which corresponds to this entry then VLOOKUP() is your friend. you would use it as such:
=VLOOKUP(MAX(C:C),C:D,2,FALSE)
Hope this helps.
Incidentaly, the best way to do your problem in VBA, the simplest way would be to create a Named Range. You can then replace the $C$2-$D11 with the name of the named range. The simplest way to do this would be to say:
Range(Range(C2),Range(C2).End(xlDown)).Name = NAmeOfYourRange
This effectively just gets cell C2, goes to the last non blank cell in the downward direction and names that range NameOfYourRange
Hope this helps :)