Excel - INDEX / MATCH with different tables and multiple criterias - excel

I have two Excel Sheets
Sheet 1:
Sheet 2:
What I'm trying to accomplish is to get excel to retrieve the date in the top row for the column that contains a value. I think I have found a way to do this without taking the Unique ID in account but I need to be able to add the ID as a criteria into this formula because my formula would only work if all the IDs are in the same order and part of both tables.
This is what I currently got : =INDEX($H$4:$Z$4;MATCH(TRUE;INDEX(H6:Z6>0;0);0))
How can I take into consideration the IDs in a way that excel matches the IDs also?

=IFERROR(EOMONTH(AGGREGATE(14,6,1/(INDEX($H$5:$Z$16,MATCH($G22,$G$5:$G$16,0),)<>"")*($H$4:$Z$4),1),0),"")
Older versions of Excel need this entered with ctrl+shift+enter.
This searches your data for the row where the ID meets the criteria (in this example I used G22 for the ID to match).
Aggregate checks for a non-empty cell in that range and returns the value in the header. EOMONTH then returns the last day of that month.
If there's no values or matching ID's it returns as blank.

Related

Excel count Unique ID's between two dates + a distinct count of another column for each ID

I am struggling with an Excel formula. I am trying to count the number of Unique ID's between two dates (I have that formula working), but I also want to count the SignUpRoles for each unique ID that qualified between the two dates. I am using O365.
Here is how I am capturing the UserId counts in K10:14
=SUM(IF(FREQUENCY(IF(Weartime13[RecordDate]>=K5,IF(Weartime13[RecordDate]<=J5,MATCH(Weartime13[UserId],Weartime13[UserId],0))),ROW(Weartime13[UserId])-ROW(A5)+1),1))
Here is the worksheet I am working with: RDS_Report
Screenshot:
RDS Report Screenshot
So what I mean by adding another 'if' is that in L14 (for example) you would have
=SUM(IF(FREQUENCY(IF(Weartime13[RecordDate]>=O5,IF(Weartime13[RecordDate]<=J5,IF(Weartime13[SignUpRole]=L9,MATCH(Weartime13[UserId],Weartime13[UserId],0)))),ROW(Weartime13[UserId])-ROW(A5)+1),1))
and in the next column that would change to M9 and N9:
=SUM(IF(FREQUENCY(IF(Weartime13[RecordDate]>=O5,IF(Weartime13[RecordDate]<=J5,IF(Weartime13[SignUpRole]=M9,MATCH(Weartime13[UserId],Weartime13[UserId],0)))),ROW(Weartime13[UserId])-ROW(A5)+1),1))
=SUM(IF(FREQUENCY(IF(Weartime13[RecordDate]>=O5,IF(Weartime13[RecordDate]<=J5,IF(Weartime13[SignUpRole]=N9,MATCH(Weartime13[UserId],Weartime13[UserId],0)))),ROW(Weartime13[UserId])-ROW(A5)+1),1))
I've filled in the last row:
EDIT
As noted by #JosWoolley, a structured reference would have been preferable to row(A5). I would suggest:
=SUM(IF(FREQUENCY(IF(Weartime13[RecordDate]>=O5,IF(Weartime13[RecordDate]<=J5,IF(Weartime13[SignUpRole]=L9,MATCH(Weartime13[UserId],Weartime13[UserId],0)))),ROW(Weartime13[UserId])-ROW(Weartime13[#Headers])),1))
But what if you want to pull these formulas across so that L9 changes automatically to M9 and N9 but it still references the same table columns? I had to look this one up and the answer is:
=SUM(IF(FREQUENCY(IF(Weartime13[[RecordDate]:[RecordDate]]>=$O5,IF(Weartime13[[RecordDate]:[RecordDate]]<=$J5,IF(Weartime13[[SignUpRole]:[SignUpRole]]=L9,MATCH(Weartime13[[UserId]:[UserId]],Weartime13[[UserId]:[UserId]],0)))),ROW(Weartime13[[UserId]:[UserId]])-ROW(Weartime13[#Headers])),1))
Formula for the last row using count & filter would be
=COUNT(UNIQUE(FILTER(Weartime13[UserId],(Weartime13[RecordDate]<=J5)*(Weartime13[RecordDate]>=O5))))
for the total and
=COUNT(UNIQUE(FILTER(Weartime13[[UserId]:[UserId]],(Weartime13[[RecordDate]:[RecordDate]]<=$J5)*(Weartime13[[RecordDate]:[RecordDate]]>=$O5)*(Weartime13[[SignUpRole]:[SignUpRole]]=L9))))
pulled across for the SignUpRole breakdown, assuming UserId is numeric.
But what if you wanted a single formula that could be pulled both down and across for the whole range of dates and roles? This could be arranged as follows:
=COUNT(UNIQUE(FILTER(Weartime13[UserId],(Weartime13[RecordDate]<=J$5)*(Weartime13[RecordDate]>=INDEX($K$5:$O$5,ROW()-ROW($9:$9))))))
for the total and
=COUNT(UNIQUE(FILTER(Weartime13[[UserId]:[UserId]],(Weartime13[[RecordDate]:[RecordDate]]<=$J$5)*(Weartime13[[RecordDate]:[RecordDate]]>=INDEX($K$5:$O$5,ROW()-ROW($9:$9)))*(Weartime13[[SignUpRole]:[SignUpRole]]=L$9))))
for the role columns.
Is there a simpler way of doing this whole thing? Maybe with pivot tables or perhaps power query, but that would be a separate answer :-)

Combining COUNTIFS with a VLOOKUP

I have looked through other posts on here and cannot find the solution I need.
I am currently using this formula:
=COUNTIFS(Tracking!$F$3:$XA$3,$F1,Tracking!$F4:$XA4,"~*")
This is counting all the * values that match to the reference "Attainment" (This is cell F1), but is relying on my 2 worksheets to have the people listed in exactly the same order. What I really want is the countif to calculate based on matching the person ID.
I have 2 sheets that use a unique ID for each person. I want to be able to match this ID and then run the countif, so in essence combine a VLOOKUP with the COUNTIFS. I did try adding another criteraia to the COUNTIFS but this doesn't seem to work. No IDs are repeated in either sheet. The unique ID defines each row and the row holds a very large amount of grade data for the person.
Sample Data
I think you could accomplish this using this formula in F3
=COUNTIF(INDIRECT("Tracking!"&MATCH(A3,Tracking!$A:$A,0)&":"&MATCH(A3,Tracking!$A:$A,0)),"*~*")
This is using the row number of the match to COUNTIFS any cells with a * in that row.

Excel: Count Unique Dates for set of multiple criteria

I have a large spreadsheet with many data columns and dates . Column B is the date column and there are multiple rows of duplicate dates with different data in the following columns. I'm trying to write a formula to give me a count of how many unique dates there were given different criteria. I did this formula entered as an array and it worked perfectly.
=COUNT(1/FREQUENCY(IF(('NA Trades'!D:D="TSX D3")*('NA Trades'!DX:DX>16),IF('NA Trades'!B:B<>"",'NA Trades'!B:B)),IF(('NA Trades'!D:D="TSX D3")*('NA Trades'!DX:DX>16),IF('NA Trades'!B:B<>"",'NA Trades'!B:B))))
I tried expanding on this and adding more criteria but it doesn't seem to be working and giving me a result of 0. This is the array formula I tried with the added criteria
'=COUNT(1/FREQUENCY(IF(('NA Trades'!D:D="TSX D3")*('NA Trades'!DX:DX>16)*('NA Trades'!DQ:DQ<-2.6),IF('NA Trades'!B:B<>"",'NA Trades'!B:B)),IF(('NA Trades'!D:D="TSX D3")*('NA Trades'!DX:DX>16)*('NA Trades'!DQ:DQ<-2.6),IF('NA Trades'!B:B<>"",'NA Trades'!B:B))))
Where did I go wrong with the second formula and how can I format this formula so I can continue to add more criteria?
Your formula seems to be working fine, are you sure you have the correct data in your newly added column? BTW, I would suggest that you use named ranges or a table - it's easier to read.

Return last date something was entered into one column with criteria from another column

I'm working with a set of data in excel. Data is entered into rows for items specified in columns. The first column contains a date. A cell in the same row of one of the columns contains the name of a person and in another cell in the same row but different column may contain a number larger than zero (or it may be empty).
I need to create a formula which returns the date when a number larger than zero was last entered into that column for a specific name. This is a "living list" which keeps on growing and the same names appear in different rows, sometimes with a number in the column a mentioned and sometimes not.
I found an old thread on this site on a similar subject which got me as far as knowing the date of the last entry containing the persons name but I'm still not able to configure it to show me when that specific person also had a number larger than zero in that column.
Here's the thread: How to get the newest value from a column with conditions
My current formula looks like this:
=INDEX($A:$A,MATCH(MAX(IF($G:$G=Sheet7!C5,$A:$A,0)),IF($G:$G=Sheet7!C5,$A:$A,"")))
CTRL+SHIFT+ENTER
Column A contains the dates
Column G contains the names (and "Sheet7!C5" is a reference to a name)
The value column I need to add to the mix is column AY
I feel there must be a simple solution (a small add on to the formula) to solve this but I always end up with an error.
Thanks in advance :)
Edit: Here is a simplified example of the data entry and output list needed.
For this you need to sort the date DESCENDING and format the table as Excel Table
Edit: you can sort the date ascending. See explanation at the end.
Using your example, then the formula will be
=INDEX(TableData[Activity A], MATCH($B14, TableData[Employee initials], 0))
This works just like the usual VLOOKUP or INDEX MATCH, fetching the first date on an activity matching the employee initials.
You can use VLOOKUP, but you'll need to dynamically name the range of each columns.
Edit: Just today I found an interesting behavior of MATCH when it found multiple matching values. If you use 1 instead of 0, then it will fetch the last matching value on the list.
So, you can use this formula instead in ASCENDING table.
=INDEX(TableData[Activity A], MATCH($B14, TableData[Employee initials], 1))

EXCEL: How to merge 2 sets of customer data

I am sure this question has a really easy answer, but after extensive research I have somehow not found what I was looking for. I am not an excel pro, but do have some experience with it.
Basically I have 2 sets of data that is indexed by customer account number and gives certain values, such as sales, profits, costs etc in the one file and sales rep responsible, amount of times contacted in the other file.
My goal now is to get these two files into one, so that I have the customer ID in the first column and all the data respective to that customer number in the columns next to it on one sheet.
However the customer numbers from the two sheets are not sorted in any way so I cant just copy and paste it and i am dealing with quite a large data set so I cannot just do it manually. additionally there are more customers id's in the first sheet than in the second, since some data is missing for a certain amount of the customers.
How can I basically automatically merge the data belonging to each customer so that it ends up being displayed in one row?
I recommend that you approach the merging of these two lists by creating a 3rd, comprehensive listing, which pulls from your raw data files.
Setting up your new Results Sheet
Assume that one list is in Book1, sheet1, and the other list is in Book2, sheet1. Open up a new excel file. Put the headers along the top. Next, you will create an index which shows all unique customer ID numbers, sorted by number. This will only work if there are no duplicate ID's (except for the ones which refer to the same cusotmer).
Copy the Customer ID column manually from Book1 into the New book. Copy the customer ID's from Book2 manually, underneath the Book1 customers, in the same column in the New book. Highlight the customer ID column. Go to the Data ribbon, then Remove Duplicates. Then rightclick your data and click 'sort'. This will leave you with an ordered customer ID column, and all other fields under the other headings will be blank.
Vlookup Formula
Next, you will use 2 vlookup formulas, similar to what #StaceyBurns recommends below. Vlookup takes a specific unique value, and looks for that value on the leftmost column of a datablock. Then it finds the first time there's a match for that value, and returns a value from a cell on that row, a given number of columns away. So for example:
=VLOOKUP(A1,B1:D5,2,FALSE)
Says: Take the unique value found in A1, look for that value in column B, from row 1:5, and return the 2nd column's result out of the datablock B:D (column C). So if A1 was the same as B3, this formula would provide the result for C3. FALSE means it would try and approximate your value if there's no match.
Assume customer indexes for all files are in column A. Assume also that all other headers are in the same order, let's say from A1:H1. Your formula to use VLOOKUP in the new workbook would be as follows - put this in B2:
=VLOOKUP($A2,[Book1.xlsx]Sheet1!$A:$H,column(),FALSE)
This gives you the matching amount under Sheet1's column B header, where Sheet1!'s customer ID matches the customer ID shown in cell A2 of the New book. However, we need to know whether it was able to properly pick up a value from Book1 - because we know that some data is incomplete. So, let's check if the above result is either a number, or text:
Determining if Results are found in Sheet1
=OR(ISTEXT(VLOOKUP($A2,[Book1.xlsx]Sheet1!$A:$H,COLUMN(),FALSE)),ISNUM(VLOOKUP($A2,[Book1.xlsx]Sheet1!$A:$H,COLUMN(),FALSE)))
This will return TRUE if the result is either a Number, or Text. So it will return FALSE if either no match is found for that ID number on Book1 Sheet1, or if the result is a blank cell. So now we put that inside of an IF statement - if it returns true, we want the result from Book1. If it returns false, we want to attempt to pull the result from Book2, through the exact same formula. This whole thing will look like this:
Final Formula
=IF(OR(ISTEXT(VLOOKUP($A2,[Book1.xlsx]Sheet1!$A:$H,COLUMN(),FALSE)),ISNUM(VLOOKUP($A2,[Book1.xlsx]Sheet1!$A:$H,COLUMN(),FALSE))),VLOOKUP($A2,[Book1.xlsx]Sheet1!$A:$H,COLUMN(),FALSE),VLOOKUP($A2,[Book2.xlsx]Sheet1!$A:$H,COLUMN(),FALSE))
Now, it will try to find the match from Book1 - if there's no match for the ID, or if the match returns a blank value for that header, then it will try to find a match from Book2. If it finds no match there, it will return #N/A! (which shouldn't happen, because that means you've deleted one of the customer ID's that we pulled directly from Book1 & Book2). It might return a blank cell if that data piece is not in either sheet. This formula can be copied from B2 all the way to the bottom right of your data block in your results sheet.
You can use the VLOOKUP function on the first sheet to bring the data from the second sheet in.
So for example, take an empty column on your first sheet and add the VLOOKUP function which looks like this:
=VLOOKUP(cell to lookup,
set of data on 2nd file,
column index on 2nd file of data you want,
TRUE/FALSE Boolean to ask for either close match or exact match )
If your Customer ID is in column A and your second sheet looks like this:
A1 Customer ID
B2 Sales Rep
C3 Number of Times Contacted
then you would do a look up first for the Sales Rep:
=VLOOKUP(A1,Sheet2!$A$1:$C$15,2,FALSE)
Then double click on the bottom right corner of this cell to populate the formula for all your rows.
Then do the same in a new cell for the Number of Times Contacted:
=VLOOKUP(A1,Sheet2!$A$1:$C$15,3,FALSE)
(Note I used C15 as an example in the above VLOOKUP. It should be the number of rows you have on file 2)
More info:
https://support.office.com/en-us/article/VLOOKUP-function-0bbc8083-26fe-4963-8ab8-93a18ad188a1

Resources