I have a sheet that updates from a query, attached example. The query is formatted so that the dates are from latest to oldest. I need to pull data from the rows based on the last entry of a specific item that is made each month. There are multiple entries but I only care about the counts for 'Cross1'. So I need the last entry for each of these every January, then February, and so on. This is updated each month. I was conchatenating the date and the description columns for my VLOOKUP.
Originally, I had no problem using a VLOOKUP that just found the entry based on the last day of the prior month, as there was always an entry on the final day of the month. However, the users have now changed the data so that it may not update all the way through the month due to breaks, meetings, vacations, etc. So now my formulas do not work for those months and they will be random. You can see this in the attachment, which I pulled from halfway through December. You can see that Cross1 disappears after the 20th. It has entries for the 21st but the counts are empty. I need to pull the last entry for each month of Cross1 that has the counts filled in. In this case, 12/20, NOT 12/21.
I then tried alternatives such as the LOOKUP function which seemed to be what I needed. However, the function assumes that the data is sorted in the opposite order of my sheet. So, it works and finds what I need, but in the wrong direction (finds the FIRST entry instead). I have asked, and cannot change the query data. So that option is out.
This formula works if the data is sorted with the last date at the top: =LOOKUP(2,1/(c$2:c5995=D4786),a$2:a5995). However, I need to also have it verify that it is the last entry AND there are counts present. In other words, 12/21 would NOT be the entry I want. I would want 12/20 in this example. Thanks to #ronrosenfeld for helping me flesh out my question.
So I am hoping someone has a suggestion. I can go the VBA route but I was thinking there might be something simpler?
Here's one way using array formulas:
Related
I have an Excel sheet with over 1,500 rows of data. Each row tracks an employees start and stop time for a specific task and order number. I want to add up the total time for each person and/or location.
I tried VLOOKUP to try and do this, but it just returns an error. For example, if I want to look for Karen's total work time, I would do something like VLOOKUP(Karen,F:F,9,TRUE). What I get in return is an #REF!. I suspect this has to do with there being something like 100 rows that are related to Karen's work and the VLOOKUP isn't going to add all the values found together.
What I want is for the output, in one cell, to show the total time. I figured I might have to do something were it finds all of Karen's times and dumps them into a new column, and from there, I can sum them all up into a single cell to get the total time.
Example of Excel document
Like BigBen said in his comment, you should use SUMIFS to achieve that, along with a new column like you figured out.
I made a simple sheet in Google Sheets to exemplify it (functions used are the same in Excel).
Here's the link to it, and below is an image of it's contents:
I want to be able to dynamically add a value from a lookup table depending on whether or not a value exists.
This seems like a question that should be solvable with some kind of 'lookup' command, but I can't figure it out.
I've made this a public worksheet anyone can see: https://docs.google.com/spreadsheets/d/10r7oxMEFU6tpJ32zxSuzk4bEtWyAnb7PGtzDxBy8gq4/edit?usp=sharing
There are four columns of names, but it only needs to work with one (clearly).
Let me be more specific. In the linked Google sheet, cell B31 is key.
Here's the user experience: If you put a value into a cell then that means you (assuming you're Joe) want to visit that location for X days (whatever value you input). But then let's say you put another value in a cell further down the list, so now you want to go from the first location to the second, and spend Y days at this new location. The formula in cell B31 should use the table of hours from the "Distances" tab and add that time to the total time that it's calculating.
In this way you can magically plan your trip. The value at the bottom of the column (B31) will be the day your trip needs to finish on to do all the things you want to do, including the travel time between the locations you chose.
Went on a hike, realized I could use another column.
The answer is now on that public sheet, I created a new column for 'Joe' with the following formula which calculates the rolling new date.
=G2+B3+IF(ISBLANK($B3),0,(INDEX(Distances!$B$2:$AD$30,MATCH(INDIRECT("Trip Planner!A"&(COUNTA(B$2:B3)+1)),Distances!$B$1:$AD$1,0),MATCH(INDIRECT("Trip Planner!A"&COUNTA(B$2:B3)),Distances!$A$2:$A$30,0)))/24)
Basically, the logic goes, take the previous time plus the time spent at this location... THEN (assuming the value at this location exists) use 2-column lookup (that is, an index with two match calls) to dynamically find the distance from the last visited location to this one... and add that distance to the mix.
I am new to Stackoverflow, so please let me know me if there is not enough information. I have had many helpfull insights by using StackOverflow in the past, but I cannot find any helpful thread online, so I hope you can help me.
I've been working on a excel (2013) problem for a while now. I am trying to build a marketing agenda to store and keep track of our mailing campaigns. The campaigns themselves are send via another system, but we miss the ability to plan our mailing campaigns in advance. Since we are active on different markets in Europe, we decided to have a general mailing (for all regions) and a region specific mailing campaign (both are in the same agenda). Besides this we also want to display the mailing focus (different brands). It is my idea to return this as visual as possible (to make it usable for all users). I have add a small picture to show my desired end-result (however without any data at this moment).
At this moment, the users are going to use a (Google)form to enter the campaign information and this data is downloaded to the worksheet (by doing so all users can add new campaigns and everyone always has access to the most recent data). This part works well.
I am using a helper sheet to check if the dates fall in a campaign range, if it does fall in a campaign range it should return the mailing ID (also the row number). I have another form which uses this data to search for the right brand and displays visually (with a lot of conditional formatting).
The problem arises in the helper sheet (when I check if a date fall into a campaign range). I have been able to get it working (more or less) with the following formula:
=IF(SUMPRODUCT(--(CountryHelper!$C$2:$C$100<=$B4);--(CountryHelper!$D$2:$D$100>=$B4);RIJ(CountryHelper!$C$2:$C$100))=0;"";INDEX(CountryHelper!$A$2:$A$100;SOMPRODUCT(--(CountryHelper!$C$2:$C$100<=$B4);--(CountryHelper!$D$2:$D$100>=$B4);ROW(CountryHelper!$A$2:$A$100))))
In this formula, CountryHelper!C:C is referencing the StartDate of the mailing campaing. D:D will reference the column of the EndDates and A:A has the mailing ID. Cell B4 is the date that needs to be checked.
At first it looked this worked perfectly. If a date fell in a date range then it would return the ID. After a little playing around with this a problem came to light. It only works with non overlapping dates, once dates overlap excel will add the row numbers together and it would not work any more.
Is it possible to get the sumproduct formula working and returning only the first ID. I am aware that I then have to make another 2 formulas which return the second and third ID ( I am certain we do not get more than 3 overlapping dates). This is also the part where I get lost. I've tried to use a MIN and MAX variation wit the following sumproduct formula:
=SUMPRODUCT(--(CountryHelper!$C$2:$C$100<=$B4);--(CountryHelper_RSEU!$D$1:$D$100>=$B4);ROW(CountryHelper!$C$1:$C$100))
This will return either a 0 (with MIN) or 100 (With MAX). I think this is caused by the formula (for now it only searches the first 99 rows). I also have ventured into VBA / UDF to get this done, but as I understand it this is not possible.
Anyway, I am sorry for the long story, I hope that my problem is clear and you can help me. If you need any more information.
Thank you!
empty Marketing Agenda overview
The SUMPRODUCT is a kind of swiss army knife Excel function. But here it is wrong because, as you already have seen, it really calculates a SUM at the end. Mostly it works because it first multiplies the 0 or 1 of the conditions with the row numbers so only the row numbers which fulfills the conditions comes into the sum. But if two or more row numbers fulfil the conditions then they were added together.
Are you familiar with array formulas? The following array formula should be what you want:
{=INDEX(CountryHelper!$A$2:$A$100;MIN(IF((CountryHelper!$C$2:$C$100<=$B4)*(CountryHelper!$D$2:$D$100>=$B4);ROW(CountryHelper!$A$2:$A$100)-1)))}
To create a array formula put the formula into the cell without the curly brackets and then press [Ctrl]+[Shift]+[Enter]. Then the curly brackets should appear automaticaly.
How it works:
{IF((CountryHelper!$C$2:$C$100<=$B4)*(CountryHelper!$D$2:$D$100>=$B4);ROW(CountryHelper!$A$2:$A$100)-1)}
Gets a array of row numbers or FALSE {FALSE, rowNumber, FALSE, ...}. If both conditions are fulfilled then it gets the row number - 1, if not then it gets FALSE.
The MIN function then gets the smallest (row number - 1) from this array.
The INDEX then indicates this smallest (row number - 1) which fulfills the conditions.
It subtracts 1 from the row number because your INDEX range starts at row 2. If the row number 2 fulfills the conditions then it is the index 1 within this range, if row number 3 fulfills the conditions, it is the index 2 and so on.
Why it only works as array formula? Because the IF function do not creates a array by default even if their "Value_if_true" is a range. Within the array context it does exact this.
So I am trying to come up with a ranking system that will start at 1, and increment for every different client we have, and reseting each month.
Heres what I have:
=SUMPRODUCT(--([Client]=[#[Client]]), --([Receive Date]> [#[Receive Date]]) )+1
When this is entered, a #VALUE is returned to the cell, however, when I use
=SUMPRODUCT(--([Client]=[#[Client]]), --([Sales Rep]> [#[Sales Rep]]) )+1
Or another column (that is not a date) everything seems to work out fine. Although, obviously, that makes the ranking on a rep by rep and client basis rather than month.
Any suggestions as to why the date column isn't working and how to fix it?
Edit: Oops, forgot to include this, since I want to reset the ranking every month, I have another column that concatenates the month and year, so a Receive Date of 3/10/2014 would become "3 2014".
Then I use the:
=SUMPRODUCT(--([Client]=[#[Client]]), --([Concat Date]> [#[Concat Date]]) )+1
And thats where things get squirrelly.
Edit 2:
Alright, so I think I figured out the formula, which I constructed in this dummy workbook. Everything works perfectly here! But when I copy and paste it into the actual workbook I'm using, the #VALUE error pops up. I've checked the formatting of each corresponding column from my test file to my real one. Has me totally stumped, thoughts?
Now that you added in the edit of Concat Date, it makes sense... My belief is that you probably are creating that field as text rather than a date and so your comparison operatir will no longer work.
So, suppose your sheet had your dates in column A beginning in A2 - You could create the Concat Date field using the following formula:
=DATE(YEAR(A2),MONTH(A2),1)
OR
=EOMONTH(A2,-1)+1
In effect, it will give you the first day of the month for any date BUT it will still be a date, so your comparison operator will still work.
PS - You can still use cell formatting to make it look like `3 20141 if you really wanted to, but the most important part is that it is a date value so you can use it for comparisons!!
Hope this does the trick!!
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 :)