Finding MIN Invoice Number Per Customer and Removing All Rows That Don't Match - excel

I have an Excel file that shows online sales data. There are multiple columns, as you would expect, two of which are Customer ID and Invoice Number.
My aim is to only keep rows where the Invoice Number is the first (or MIN) Invoice Number for each Customer.
On a duplicate tab, we want the same thing, but only for the second Invoice Number per Customer (i.e. the second purchase).
On a side note, there can be multiple rows for the same Customer ID and same Invoice Number because the rows are at Item level, so it may look like this:
Row 1: Customer ID = 24; Invoice Number = 1014; Item = Jelly Beans
Row 2: Customer ID = 24; Invoice Number = 1014; Item = Candy Bars
So, that's okay. We just want to make sure any rows where the Customer's Invoice Number does not reflect their first purchase (or second purchase, in the second instance) is removed from the spreadsheet.
Is there a VBA (or even just functions) to achieve this? Even in steps: such as first highlighting those rows and then using another VBA to delete rows that are highlighted?
Again, in a nutshell I'm looking to only keep rows with the MIN(Invoice Number) per Customer ID.

Use COUNTIFS to count the number of times the customer number has appeared. Use a reference that is anchored to the first cell and changes as you drag down.
Assuming your customer numbers are in column A, insert this into B1 and copy down:
=COUNTIFS($A$1:A1,A1)
Filter on 1 or 2 accordingly.
Edit:
I didn't realise that you only wanted the first row. You can exploit the fact that MATCH will return the first result and check if it equals the row number:
=MATCH(A1,A:A,0)=ROW(A1)
Note that you may need to offset MATCH slightly if your data doesn't start from row 1. For example, if your data starts in row 3, you will need to offset your MATCH result by 2:
=MATCH(A1,A:A,0)+2=ROW(A1)
Now you can filter on the first column equalling 1 or 2 and the second column equalling TRUE.

Related

Sum of specific number of rows for a id in excel

I am pretty new to excel formulas. I want to calculate the sum of prices for every unique id. Using SUMIF I was able to do that for every unique id but I only want to calculate the sum of a number of rows for that id.
=SumIF(A:A;C2;B:B)
Sample data is attached. Actual data set is quite large. For Example, For Id 1, I only want to calculate the sum of first 3 rows (Column price) corressponding to that id, for id 2 the sum of first 4 rows and so on.
Sample data:
This formula works for sorted and non sorted data:
=SUMIF($A$2:INDEX(A:A,AGGREGATE(15,6,ROW($A$2:$A$20)/($A$2:$A$20=C2),D2)),C2,$B$2:INDEX(B:B,AGGREGATE(15,6,ROW($A$2:$A$20)/($A$2:$A$20=C2),D2)))
Enter this as an array formula (ctrl+shift+enter):
=IFERROR(SUMPRODUCT(IF(ROW($A$2:$A$20)>SMALL(IF($A$2:$A$20=C2,ROW($A$2:$A$20),FALSE),MIN(D2,COUNTIF($A$2:$A$20,C2))),0,1),IF($A$2:$A$20=C2,1,0),$B$2:$B$20),0)

Conditional Unique ID for each record excel

I have two values in different columns. Column A have Department name i.e. HR, Admin and Ops. and column be have date. I want Unique ID in column C based on Combination of Column A & B and Unique number at the end.
Unique ID: HR-Aug-16-1
Admin-Aug-16-1
this number will be repeat till the combination of Column A and B repeated 50 times after 50 times last value will be increased by +1. i.e.
HR-Aug-16-2
Admin-Aug-16-2
Right now I am using formula,
=A1&"-"&TEXT(B1,"mmm-yy")&"-1"
In C1 as a standard formula,
=A1&"-"&TEXT(B1,"mmm-yy")&CHAR(45)&INT((SUMPRODUCT(--(A$1:A1&TEXT(B$1:B1, "mmm-yy")=A1&TEXT(B1, "mmm-yy")))-1)/5)+1
I've set this to repeat after 5 for an example. I'll leave it to you to change the modifier to 50. Fill down as necessary.

Need help in excel formula

1) I have two tables. 1st table contains data for more then 20,000 rows and 2nd table I already have the following columns details i.e. Region, Item, Number and I just have to get the Total value of the product from the 1st table
2) There are two types of prices in the 1st table . One is Retail Price and Another one is a Wholesale price
3) In each of the regions Rep, Item and Numbers are same in most of the cases, but the Total price is different
4) I am able to get the Total price details in 2nd table through vlookup formula (After concatinating the following columns i.e. Region, Item and Number from both the tables) wherever there is an account number for retail price
5) Currently I am manually updating "Total Price" details in 2nd table for Wholesale price which is taking lot of time.
Is it possible to build a formula to get the wholesale price details in the 2nd table, since there are more then one account number, but the price is same
If the wholesale price is the lowest price for the specific item, then you can find it with the formulas MIN and IF.
Based on your screen shot:
D is the column with the list of items
I5 is the cell with the item name for which you want to find the wholesale price
F is the column with the list of prices
If you enter the following formula in cell K5, it should find the lowest price for pencils
=MIN(IF(D:D=I5,F:F))
On this link, there is an explanation if you want to use multiple criteria.
http://www.contextures.com/excelminmaxfunction.html
try the sumifs function.
It takes multiple arguments and criteria. So it should look something like:
cell value at j5 = sumifs(f3:f23, b3:b23, h5, d3:d23, i5....)
you need to mark off which rows in your first table are wholesale selling. So it should be a column of some kind. Once you do that, let's say in column G, then you add onto the sumifs function...
, g3:g23, L5)
What you're doing is summing up all of the values in column F where h5 (region) matches in b3:b23, i5 (item) match in d3:d23, and where L5 (retail type) match in a new column g2:g23.
This will find all of the values that match that criteria exactly.
Vlookup is useful, but it's harder to scale IMO than the advanced if functions.
SUMIFS is probably the better way to go on this one, but as an alternative there is also SUMPRODUCT.
=SUMPRODUCT(($H3=$B$3:$B$20004)*($I3=$D$3:$D$20004)*($J3=$E$3:$E$20004)*($F$3:$F$20004))
The * acts as an AND statement in a logical check, and each of the ($H3=$B$3:$B$20004) is a logical check. When the row is true it will evaluate to 1. When it is false it will evaluate to 0. in the end you wind up with a list of prices or 0s that get summed. The end result is the sum of everything that matches your criteria.
The danger of using this formula is that it can get labour intensive as it is performing array calculations without being an array formula.

Excel - How to copy rows and discard others based on today's date?

I have a worksheet, and in one sheet called Payments, every row, on column A has a date in ascending order, on column C there's a client name, on column E there's a monetary value and on column G there's a Yes/No Checkbox.
The Dates sometimes repeat themselves, but the other values, do not (the Y/N/ Checkbox also repeat themselves). So, sometimes i have:
m / d / y
02/02/2014 - Client X - 100,00 - y;
02/02/2014 - Client Z - 120,00 - n;
02/03/2014 - Client W - 110,00 - n;
etc.
What I need is this: on another sheet called Today's Dues, in the same worksheet, when colum A from Payments sheet (the date column) is today's date, the entire row from that column from A to G) is copied to Todays Due sheet. And the same would apply to all the other rows where the A column had todays date. But, tomorrow, that sheet would need to update itself, so the information from yesterday would not be there anymore, just the new rows with the new day's date.
Since there is no more than 10 payments a day, the space available on Todays Due would not need to be bigger than 10 rows, but would have to get information from the entire A column of Payments sheet.
What is was thinking was to create a Macro that would duplicate ALL data from Payments sheet, then automatically apply a filter with todays date. This Macro would be the first thing happening on opening. But this has been proving to be very frustrating. I cant seem to make Excel recognize my dates as dates, only as text, i tried everything.
Any help, or a more elegant solution, please ?
thanks
Assuming multiple rows of same date are in order, these should work.
Date:
=IF(INDEX(Payments!A:A,MATCH(TODAY(),Payments!A:A,0)+ROW()-2)=0,"",INDEX(Payments!A:A,MATCH(TODAY(),Payments!A:A,0)+ROW()-2))
Client Name:
=IFERROR(INDEX(Payments!$C:$C,MATCH($A2,Payments!$A:$A,0)+ROW()-2),"")
Value:
=IFERROR(INDEX(Payments!$E:$E,MATCH($A2,Payments!$A:$A,0)+ROW()-2),"")
Yes/No:
=IFERROR(INDEX(Payments!$G:$G,MATCH($A2,Payments!$A:$A,0)+ROW()-2),"")
Put each formula in consecutive columns to get your 4 unique values. Drag these down for 10 rows to collect all possible values.
**Note: The 2 in "ROW()-2" will be whatever row number you start this on. I used 2 since I put headers in the first row.

Excel VBA Lookup Methods

I have an issue that I've been scratching my head at; I've looked into the Index:Match lookup method, and V/HLookup, but I'm not sure these will help just yet. Here's what's happening:
I have two worksheets in excel-2007. One has a Customer ID column (which does and will have duplicate ID's in the instance that the customer did "x activity" more than one time in a month) and then the date that this happened in another column. The second sheet is for giving an overview of a specific day, IE what happened on 7-1-13.
The issue is that my raw data sheet is sorted via the first of the month descending, so 7-1,7-2,etc, and when I run the Vlookup, if a Customer ID has a record on 7-2 and on 7-15, the VLookup will pull data only from the 7-2 (first) row. Has anyone experienced this and found a workaround?
My current workaround would be to make either a new table for each day's data, or instead of using my VLookup of =Vlookup(A2, 'Data Sheet' A:D, 4, 0) to give the columns row numbers, like =Vlookup(A2, 'Data Sheet' A$1:D$30, 4, 0). This is a daily report, and that would be intense. Please help if you can!
(Another side note, I have one main sheet for the view, one data sheet where it's all collected, and then 30 sheets, one for each day of the month, this case being July). For each sheet, I've named them the day of the month, so I'm reflecting the data as such:
Sheets("7-1-13") has data from the 1st on it. The Data Sheet in it's entireity has data from 7-1-13 to 7-31-13. I need to reference ID's on the 1st to the data for the 1st and the 1st only.
I want to use something like this, but I'm having a hard time with it
=Vlookup(A2, 'Data Sheet', A:D (ONLY IF THE CREATE DATE OF THIS ITEM IS 7-1), 4,0)`
but of course it's not that easy :p
This may not give you your results in a format you like and still requires a bit of manual work, but without going the route of macros, I think this will get you one step closer. I thought of using an array formula to get all the IDs by a specific date.
Example:
A B
ID Date
1 5 7/1/2013
2 2 7/2/2013
3 5 7/3/2013
In this situation, I assume you want 5 from the first row to appear on your 7/1 sheet, 2 to appear on your 7/2 sheet, and 5 from the third row to appear on your 7/3 sheet
on your 7/1 sheet. you'll need to select the number of blank rows that matches your raw data (using the example above, you would be selecting A1:A3 on your 7/1 sheet). Once you have your cells selected, then enter the following formula in the formula bar and press Ctrl+Shift+Enter. This is what makes the formula an array formula.
=((Raw_DataSheet!B1:B3=DATE(2013,7,1))*1)*Raw_DataSheet!A1:A3
What this formula does is looks at all the dates in B1:B3 and finds the ones that equal 7/1/2013. Since you're using an array formula, this gives you the array {TRUE,FALSE,FALSE}. Multiply this by 1, and you get the array {1,0,0}. You now have an array that has a 1 for each row of B1:B3 that was equal to 7/1/2013. This array {1,0,0} is then multiplied by your Customer IDs {5,2,5}
5 * 1 = 5
2 * 0 = 0
5 * 0 = 0
So now your entire formula is equal to the array {5,0,0}. Since you selected A1:A3 on your 7/1 sheet, the values that should appear should be
A
ID
1 5
2 0
3 0
From here, you can always filter out the 0's and you'd just have a list of all the IDs that had the date of 7/1 from your Raw Data Sheet. You would also then replicate this for each of your sheets and just change the date in the formula...Yes, I know, way more complicated than you probably wanted but it's what I came up with!

Resources