Compare two excel tables based on unique key using formula - excel

I have two tables with same column names in excel which are getting data from two different sources based on certain calculations. We need to compare data between those two tables based on ID column value which will be provided by user in A2. I have attached snapshot of sample tables. I did try using sumproduct (as you can see in K2, but it doesn't work if any of the cell values has #NA as it's value. Please keep in mind that calculations update data for only a particular id (one row only for each table). in this example, values for only the rows with ID 200 will be updated for these two tables.
If I change value from #NA to an integer, formula (in K2) would work. Now I was even thinking about using if(And(logic1,logic2...)) to compare cell to cell values,but I don't kow how would I use it when the placement of ID's in columns C and G can vary and won't necessarly be in the same row.
Formula used:
=IF(G2:G5=A2,IF(SUMPRODUCT((G2:G5=A2)*(H2:I5))-SUMPRODUCT((C2:C5=A2)*(D2:E5))=0,"Match","No Match"),"")

This may help get you started.
=IF(AND(IF($A$2=G3,VLOOKUP(G3,C3:E6,2,0),"")=H3,IF($A$2=G3,VLOOKUP(G3,C3:E6,3,0),"")=I3),"Match","No Match")

Try following array formula:
=INDEX({"No Match","Match"},1,IFERROR(--(MATCH(COLUMNS($C$2:$E$2),MMULT(--(INDEX($C$2:$E$5,MATCH($A$2,$C$2:$C$5,0),0)=$G$2:$I$5),TRANSPOSE(COLUMN($C$2:$E$2)^0)),0)>0)+1,0))
Array formula after editing is confirmed by pressing ctrl + shift + enter

Related

Data in column instead of rows

I am getting data from SQL Server into an Excel sheet. Its a customer table containing 20 records. The columns are Customer Code, Customer Name and Customer Short Name.
What I need is instead of data coming in rows (from row 2 to row 21)... it should come in columns.. i.e. 1st three rows of column A contains respective headers (code, name and short name) and column B first row contains value of code, second row value of name and third row value of short name... same continue to column C, D, E..... till all 20 records..
Is it possible in excel?
In Excel, you can easily transpose the array with your data. Consider the following sample data in the range A1:C4:
You could now select the entire range and copy it via CTRL+C -> Paste -> Transpose (T). A second possibility would be to enter the following formula in, e.g., cell E1: =TRANSPOSE(A1:C4). This is a dynamic array formula in the current version (Microsoft 365). If you have an older version, you have to enter the formula as a legacy array formula by confirming the formula with Ctrl+Shift+Enter.
The result is as follows:
Edit: Dynamic setting of range
Theoretically, assuming that the data structure remains the same in terms of the number of columns and rows, the formulaic approach will update the transposed array accordingly as the original data is updated. In the specification above, the range A1:C4 is hard coded. While it is very likely that the number of columns will remain the same (could also be dynamically adjusted), in practice additional rows could be added/deleted from the data. In this case, you can specify the number of rows dynamically, which solves this problem:
=TRANSPOSE(INDEX(A:C,1,1):INDEX(A:C,COUNTA(A:A),3))

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

Using a keyword(s) to return results

I have a workbook what has a tab (Clarity) with a large range of historical information (columns A-IV & c15k rows).
I have created a second tab to search the Clarity information using 1 or more keywords.
Cell C2 is the keyword input cell and I want the results (using a small subset of 12 of the columns) to be displayed in a separate table.
I have created the following formula in cell C5 (using ctrl shift enter):
{=IFERROR(INDEX(Name,SMALL(IF(ISNUMBER(SEARCH($C$2,Name)),ROW(Name)-ROW(INDEX(Name,1,1))+1),ROWS(C$5:C6))),"")}
and then copied this formula down through to cell C30. I have then created VLOOKUPs in the other 11 columns based on the information in column C.
It seems to work but it creates duplicate records where there aren't in the source data.
It only searches on one column (column D in the Clarity tab, which I have named "name")
It takes about 10-20 seconds between entering the keyword and getting the results.
If I try and make it search all columns, I get no results - Is there a problem with my formula? Is there a more efficient way of doing this?
=IFERROR(INDEX(Name,SMALL(IF(ISNUMBER(SEARCH($B$2,Name)),ROW(Name)-ROW(INDEX(Name,1))+1),ROW(1:1))),"")
I updated ROWS(C$5:C6) to just reference ROW(1:1) so that the first smallest match is found first and the row will update when the formula is dragged down.
Let's say you want to evaluate against the whole row, make the name manager store the whole concatenated row as each array object.

Excel array formula help required - multiple criteria, multiple results

I need help - currently, all of my research on this topic is making things worse.
I have a worksheet with an undetermined amount of data (new data is being added constantly)
From this worksheet I have to collate all valid results that match the criterion of; no data entry in column L, and the data of column A must fall within the current month (I also need the same again but for the month previous... I figure I can easily adjust a single formula...)
Ideally, the returned results should list in a column the data pulled from the source sheet from column B
The results are being inserted into a dashboard page of a different tab within the same workbook.
I really would appreciate a little help.
Say our data is like:
Pick a cell, say M1, and enter the array formula:
=TEXTJOIN(",",TRUE,IF(($L$1:$L$26="")*(MONTH($A$1:$A$26)=3),$B$1:$B$26,""))
where the 3 stands for March:
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key. If this is done correctly, the formula will appear with curly braces around it in the Formula Bar.

Excel: Return Multiple Items with One Lookup Value but on a different sheet

My formula works, but only if its in the same page, and along the same rows
Formula:
=(INDEX($C$1:$D$4,SMALL(IF($C$1:$C$4=$F$2,ROW($C$1:$C$4)),COLUMNS(D1:D4)),2))
Note: Column G has the formula, what it does it look for value in F2 (which is 1.2) within the columns of C & D, and extracts the respective data in column D. So in this case, it would extract the data in column G.
Question: Now what do I do if I want this to occur from different sheets, or even different workbooks? I need to do this exact same thing, extract the data that is in column c and d (which is on a different workbook) to my workbook.
Every time I try, I get a value error.
Bonus: I'm also trying to get the date that is closest to today's date, I have this formula here:
=IF(COUNT(G2:G5)>0,INDEX(G2:G5,MATCH(MIN(ABS(G2:G5-$D10)),ABS(G2:G5-$D10),0)),"")
Where D10 is just equal to =TODAY() and this entire formula works by pressing ctrl+shift+enter
If you can also include this into the formula so that it just spits out the closest date in G2 rather than spit out all the dates. But it is not necessary, just helps a lot.
For your "Closest to today problem", I was trying to spread the difference of the date or a comparison of the date just like in your example. This is just not working out. I solved the problem by adding another column. I do not know if this is a valid option for you or not, but here is what I have. Assuming H is available or you can insert a new column H. use this dragged down for each row - in your exampl 2 thorugh 5.
=ABS(D$10-G2)
Then add this in H10 or wherever you see fit
=D10-(MIN(H2:H5))
Here is an excel-ish example
5/12/2014 =ABS(D$10-G2)
5/13/2015 =ABS(D$10-G3)
5/14/2014 =ABS(D$10-G4)
5/15/2014 =ABS(D$10-G5)
6/6/2016 =D10-(MIN(H2:H5))

Resources