Formula to follow addition of rows - excel

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 :)

Related

Excel multiple running totals

I'm trying to make a simple formula for multiple running totals.
Basically, it's for recording transactions for different accounts, showing the running total of that particular account for each row. So, it's impossible to use SCAN+LAMBDA function. One way to do it is to have a set of helper arrays somewhere, but here I'm using another way, by using XLOOKUP.
=C2+XLOOKUP(D2,D$1:OFFSET(D2,-1,),E$1:OFFSET(E2,-1,),0,,-1)
Basically, it looks up the last account balance above the current row of the corresponding account and add the current transaction amounnt to it. It works by draggin down to all the transaction rows.
Since the number of transactions is over 10 thousand, I was trying to minimize the file size by using named function with LAMBDA.
Name: AddtoBalance
=LAMBDA(c,c+XLOOKUP(OFFSET(c,,1),Sheet1!E$1:OFFSET(c,-1,1),Sheet1!F$1:OFFSET(c,-1,2),0,,-1))
And changed cell E2 to
=AddtoBalance(C2)
and dragged it down to all transaction rows.
However, after saving and re-opening, the cells are having errors. I have to go to Name Manager, click Edit but without doing anything and Close it. Then the cells becomes fine again. It seems to me that when re-opening a workbook, the formulas are not calculated sequentially from top to bottom. Is that right? Is there any options to change it?
I think you are going to hate me when you see this…
Put this in E2:
=SUMIF( B$2:B2, B2, C$2:C2 )
Then copy it down. Mind the dollar signs, they are important. You could place this in a named Lambda but the character count reduction is probably immaterial.
After rebooting and restarting excel, actually I could not reproduce the error. It works fine with the Lambda function now.
Whole different approach, but how about:
=LET(f,ISNUMBER(C:C),
c,FILTER(C:C,f),
d,FILTER(D:D,f),
s,SEQUENCE(COUNTA(d)),
MMULT(
(d=TRANSPOSE(d))*(s>=TRANSPOSE(s)),
c))
It first creates an array of TRUE's and FALSE's on column C:C if it contains a number. This is used to filter the values to be used from column C and D.
A sequence of the count of filtered values in column C is used to simulate it's row number in that filtered range.
Now MMULT checks row by row how many values of column D equal it's current value where the sequence number for that "row" is smaller or equal than the current.

How to count the number of occurances of values in a cell based on 2 different critera

I am trying to count (or rather to ascribe the number of total orders) of customers based on a) whether they have purchased before, and b) the date of each purchase.
The table also contains all the products ordered in a single order, each in a different line.
Column F is what I'm trying to define (I have filled these numbers in manually and highlighted for clarity).
I am trying to use COUNTIFS:
=COUNTIFS($B$2:$B3,$B3,$A$2:$A3,$A3)
However, I cannot make it work properly.
I need it to count only if
a) the entry in column B is the same as the previous entry, and
b)the date entry (column A) is different then the previous entry. Otherwise, column F should return the same value as the previous entry (so that all 'total orders' for the same email with the same date have the same total orders number.
I think I'm likely missing an 'else' statement somewhere.
Any help is greatly appreciated!
Try this formula:
=IF(B2=B1,IF(A2=A1,D1,D1+1),COUNTIFS(A$2:$A2,A2,B$2:$B2,B2))
Tested below.
In English, the formula checks if emails are equal, then if dates are equal, if so, it grabs value from above. If dates are not equal but emails are it adds one to number from above. If emails are not equal, it starts the count anew with your original COUNTIFS. Because it will always generate a 1 for first row, the structure of the IF blocks work.
I think this would work for you:
=COUNT($A2)+COUNTIFS($A$2:$A2,"<>" & $A2,$B$2:$B2,"=" & $B2)
you can add in operators inside ""s and 'concatenate' with an ampersand (&)
This formula will count any entry above the date given, as long as it is a different date and the same email. I know this is what you were asking for, but it isn't neccesarily accurate as a count of prior purchases. In order for this to be accurate you should consider a different method for recording multiple product purchases on the same date. Otherwise, just label the column "Qty of prior products purchased" as opposed to "Qty of prior purchases. :D GL, speak up if you need anything else!

excel count/sum stop count/sum match?

I have tried to see if this question has been asked before, but I can't seem to find an answer.
I have a column of cells (>3000 rows), with either a value of 1 or 0 (call this column A). The value will depend on the value in column B (which will contain either a value or nothing). The values in column B are a SUMIFS function based, summing from column C, and based on months in column D.
The values in B are paid out on the first business day of the next month. So, the SUMIFS function will calculate the dates that match the last month. This works well in theory, however, not every first business day is the first day of the month. This leads the SUMIFS function to not include everything in the correct month, and allows for some discrepancy, which, when you are dealing with people's money is not great. Further, this discrepancy is compounded across multiple periods (in some cases, there are over 100 periods, and a discrepancy of $1 in period 1 amounts to nearly $1000 in period 100)
What I am wondering is:
Is there any way that I can tell the SUMIFS function (column B) to stop when the value in column A is 0? This would tell the SUM function start the summing from the current value in column B and continue the function to the cell below the preceding value in column B.
I've seen suggestions that the MATCH function may work, but I can't see how to do this with either COUNT or SUM.
For security reasons, this solution needs to be entered into the cell, and can't be VBA. Also, it can't be too large, as it will need to be replicated across 200 worksheets in the workbook (not my file originally, and I would have done it differently, but that is another story). There is no problem entering another column or two if that is required.
Any help is gratefully appreciated.
EDIT:
Unfortunately, I can't post an image of the screenshot. I've included a similar screenshot (columns are not the same layout, but hopefully it gives the idea) here:
Rates calculations
The SUMIF formula is (for B2)
=SUMIFS(C2:C35,D2:D35,D2-1,A2:A35,1)
This works fine if I want all the values in the month, irrelevant of when the payment was made.
However, what I need the formula to do is:
SUM (C2:C35,D2:D35,D2-1, but stop when the first 0 is encountered in A2:A35)
Thanks
The INDEX function can provide a valid cell reference to stop using a MATCH function to find an exact match on 0.
This formula is a bit of a guess as there was no sample data to reference but I believe I have understood your parameters.
=SUMIFS(C2:index(C2:C35, match(0, A2:A35, 0)), D2:index(D2:D35, match(0, A2:A35, 0)), D2-1)
This seems to be something that will stand-alone and not be filled down so I have left the cell addresses relative as per your sample(s).

Excel 2013 advanced date range lookup using sumproduct

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.

Excel 2013: Count unique values or IDs in column B with a condition which needs to be filtered in column A

I am a noob in excel, hence pardon me for any mistakes made.
This question must have been answered before but I couldn't find the right string to make it work for me.
There are around 500 rows and 20 columns (Yes, it is a report)
Column A has a few values (eg: Problem, Change, Request, etc.)
Column B has ticket numbers assigned to each entry. (No, I don't work for a call center, these are Datacenter Operations tickets)
Column B has several duplicate ticket numbers, as many people worked on same ticket OR the ticket was reopened for some reason.
I wish to take a count of unique ticket numbers from Column B when the condition in Column A is Change only.
So if there are 500 ticket number 250 are duplicate for sure, and only 25% of the rest will be Change tickets.
I am not supposed to use a Pivot or filter hence asking this question.
Need a formula to retrieve the count with the condition.
I may put the formula in Sheet2 or at the extreme right column, plz don't worry about it, I will take care of those things.
Many thanks in advance.
Adding to the question,
Let me help you with some data.
Change CRQ1110001
Problem INC1110001
Change CRQ1110001
Problem INC1110001
Change CRQ1110003
Problem INC1110003
Change CRQ1110004
Problem INC1110004
Change CRQ1110004
Change CRQ1110004
Problem INC1110005
Now I wish to only consider Change here without considering duplicate values.
Maybe this helps.
Thanks again.
Based on this website count unique values and with a small change this formula should work, expand the ranges to cover your entire range.
=SUM(IF(FREQUENCY(IF(A2:A10="change",IF(LEN(B2:B10)>0,MATCH(B2:B10,B2:B10,0),""),""), IF(A2:A10="change",IF(LEN(B2:B10)>0,MATCH(B2:B10,B2:B10,0),""),""))>0,1))
Entered with ctrl+shift+enter as it's an array formula.
Note that if you do this over the entire column A:A it will take quite a bit of time to compute as it has to go through a lot of calculations in the array formula.
If your "ticket numbers" in column B are actual numbers then you can use this formula
=SUM(IF(FREQUENCY(IF(A2:A500="Change",B2:B500),B2:B500),1))
confirmed with CTRL+SHIFT+ENTER
If not numeric you need to use a version as per gtwebb's suggestion

Resources