Excel Formula or Macro to get the consolidated list from two tables - excel

Question:
Table 1 is as follows.
Name | Hours
john | 12
mark | 20
john | 10
mark | 10
Table 2 is as follows.
Name | Hours
john | 40
mark | 30
These 2 tables are in two diffent workbooks. The Data I need is as follows.
Step 1: From Table 1 I need to consolidate the Column 'Name' and should get the SUm of Column 'Hours'. (i.e) it should be populated as follows.
Table 3
Name | Hours
john | 22
mark | 30
Step 2: Once the above step is achieved I should compare the Column 'Hours' in Table 2 & Table 3 and should populated the result as true or false..

Try this formula:
=IF(SUMIF([Workbook1]Sheet1!$A$1:$B$4;A1,[Workbook1]Sheet1!$B$1:$B$4)=B1,"true","false")
It assumes that Table1 is in Workbook1, Sheet1 in range A1:B4.
I also assumed that Table2 locates in A1:B2 range. Now it's enough to place above formula in C1 cell next to Table2 and drag it down.

Create two pivot tables for both tables and compare accordingly. Then,
=GETPIVOTDATA("Hours",$A$2,"Name",A3)=GETPIVOTDATA("Hours",$A$8,"Name",A9)

Related

Excel: Matching Data in Excel. Writing an IF statement by dragging instead of manually inputting

I have two sheets. Both sheets contains two columns with Countries and Price #s. The first sheet does not have info for the Price # but the second does.
Sheet 1:
Country|Price #
Canada | Null
Brazil | Null
Spain | Null
Canada | Null
Sheet 2:
Country|Price #
Canada | 1
Spain | 2
Brazil | 3
Austria | 4
Goal: I want to fill out the Null values in sheet 1 with the corresponding numbers in sheet two. For example a 1 for Canada, 3 for Brazil, etc.
If I didn't have much data, this would be an easy IF statement in the Null cell. For example
' =IF(B2="Canada",1, IF(B2="Spain",2,IF(B2="Brazil",3,4)))
Problem is that my data contains over 50 countries so it would be tedious to write this formula. Is there a way to use the drag feature in Excel to do this? Also open to not using an IF statement.
Or you can use SUMPRODUCTif you need return numbers only:
=SUMPRODUCT(--(D1=$A$1:$A$4)*$B$1:$B$4)
Sheet2:
Sheet formula Pict 1:
Sheet Formula Pict 2:
Here the formula to be copied, choose as your need:
=filter(if(C1:C="",vlookup(B1:B,Sheet2!A1:B,2,false),""),B1:B<>"")
or
=filter(vlookup(B1:B,Sheet2!A1:B,2,false),B1:B<>"")

Excel Formula - Return unique count of range based on multiple criteria from different tables

I have three tables: Parties, Document Detail and Document. (Note, they are not table formatted, so all references are based on cell and sheet location, not table aliases)
I want to return a unique count of the parties in each Document using an Excel Formula. My problem is, I would usually use a =COUNTIFS() formula for this, which would be something like the following, which I would put in B2 of Sheet 3 (Document table):
=COUNTIFS(Sheet2!A:A,A2,Sheet2!B:B,Sheet1!A2)
But this will only return the count of one criteria at a time, not a count checking for all values of the parties table per document. I understand it should be able to be done with an array formula, but I can't figure it out. Bonus points if someone can figure out how to do it with a non-array formula!
Sheet1 - Parties Table
A
1|Parties |
+-----------------+
2|Education Officer|
3|Elder |
4|Family Support |
5|Interpreter |
Sheet2 - Document Detail Table
A B
1 |Doc ID | Party |
+-------+-----------------+
2 |FID0001|Education Officer|
3 |FID0001|Elder |
4 |FID0001|Education Officer|
5 |FID0001| |
6 |FID0001| |
7 |FID0002|Elder |
8 |FID0002|Interpreter |
9 |FID0002|Family Support |
10|FID0002| |
Sheet3 - (Desired Result) - Document Table
A B
1|Doc ID |Party Count|
+-------+-----------+
2|FID0001| 2 |
3|FID0002| 3 |
TL:DR
What combination of Excel formulas can I use to return the number of unique parties referenced in each document?
Based on this answer by Barry Houdini and expanded to include the DocID criteria
Put a helper column on Sheet2, lets say in colum C
=IFERROR(1/COUNTIFS($B:$B,$B:$B,$A:$A,$A:$A),0)
and copy down for all data rows
Then, in Sheet3 Party Count Formula is
=SUMIFS(Sheet2!$C:$C,Sheet2!$A:$A,$A:$A)
The non-Implicit Intersection versions
Sheet2 cell C1
=IFERROR(1/COUNTIFS($B:$B,$B1,$A:$A,$A1),0)
Sheet3 cell B2
=SUMIFS(Sheet2!$C:$C,Sheet2!$A:$A,$A2)

Excel formula for calculating unique occurrences in a column grouped by another column

I need to build a single Excel formula for calculating the third column in the table below based on the previous two columns.
First column shows the name of the active user
Second column shows which week number the activity occurred
The third column should in every row show the total number of unique
weeks that the user in the first colum has been active ever.
------------------------------------------------
NAME ACTIVE-IN-WEEK-NO NUM-UNIQUE-ACTIVE-WEEKS (Need a formula for this one)
------------------------------------------------
JOHN | 50 | 2
ADAM | 48 | 3
PETER | 48 | 1
JOHN | 50 | 2
JOHN | 50 | 2
ADAM | 45 | 3
ADAM | 40 | 3
PETER | 48 | 1
JOHN | 45 | 2
-------------------------------------------------
For this requirement you need to use Microsoft Query ,
refer the link given below :
http://www.excel-easy.com/examples/microsoft-query.html
To Fix this you need to write sql statement in microsoft query.
Hope this Helps.
Assuming your table is in A1:B10 (with headers in row 1), this array formula in C2:
=SUM(IF(FREQUENCY(IF($A$2:$A$10=A2,$B$2:$B$10),$B$2:$B$10)>0,1))
Copy down as required.
Regards
**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).

How to sum a row in Excel with lookup values from a column based lookup?

I have rows of values in columns AC to AU (but also some blanks)
I want to convert these values in a formula via a lookup and sum all the lookup values in a row.
For 1 cell I can use VLOOKUP(AC2,'Lookup_Table'!A2:B41,2) successfully
How do I sum the whole row of AC2 to AU2 with this kind of lookup?
Note the lookup is column oriented in a vertical lookup, the 'Lookup Table' is actually a worksheet.
This has stumped me for hours now!
| AC | AD | AE ..Ax... AU
Row 1 | 12 | 23 | 43 ..00... 67
'Lookup table' worksheet
A | B
12 | 4
23 | 2
43 | 3
67 | 5
The result should be 14 for the sample Row 1 data above
It is much easier to use an array formula (ctrl+shift+enter instead of just enter). Generally I don't like array formulas (because they are easy for the uneducated to break), but I think it will work the best in your situation apart from reformatting your sheet or using helper columns.
{=SUM(IF(AC2:AU2=Lookup_Table!A2:A41,Lookup_Table!B2:B41))}
which should have {} around the whole thing if you entered it correctly.
You need to use a combination of SUM and INDEX functions, where AB in Lookup_Table is your index column for the table, and A! is the value you wish to lookup:
=SUM(INDEX(Lookup_Table!$AC$1,MATCH(A1,Lookup_Table!$AB:$AB,0)):INDEX(Lookup_Table!$AU$1,MATCH(A1,Lookup_Table!$AB:$AB,0)))

Find two matching rows and display data from the thirt one (Excel)

So i have Two Sheets.
First sheet contains two columns
BRAND | LEFTOVER
The second sheet consists of two columns also.
BRAND | LEFTOVER (%)
So in case if the BRAND row value in the first Sheet will match the BRAND row value in the second i want to display the matching LEFTOVER (%) row value in the first sheet rows in the column LEFTOVER.
Kind of lost here.
Appreciate any ideas. Thanks.
In Sheet2:
. A | B
--------------------
1 BRAND | LEFTOVER %
2 X | Y
3 |
In Sheet1:
. A | B
--------------------
1 BRAND | LEFTOVER
2 X | =VLOOKUP(A2,Sheet2!A:B,2)
3 |
The VLookup function searches for its first parameter (in this case the value of Sheet1!A2) in the first column of the range denoted by the second parameter (in this case the leftmost column of the range containing columns A and B on Sheet2)
It then returns the value from that same row of the range that is to the right in the columns denoted by the third parameter (1 is the leftmost column where the matched value was). So in this case we use the number 2 because 1 means column A and 2 is column B (which explains why we used a two column wide range for the second parameter - it needed to encompass the column the result was in)
This isn't the only way to do this, but it is the easiest.
As Jerry stated VLOOKUP is the simplest way to do this.
HOWEVER if you have multiple/repeat instances (rows) in BRAND, VLOOKUP will only return the first record (row) that appears in your data.
If this is the case, you will need to add either a unique identifier column; and/or additional criteria to differentiate between the repeat instances.
As an example column A is used as a unique identifier to differentiate between the 2 'Nike' rows.
A B C
1 BRAND LEFTOVER
2 Nike 50
3 Adidas 25
4 Reebok 30
5 Nike 29
I feel that you can use vlookup to accomplish your goals.
Let me explain it in a bit detail.Suppose you have two sheets as:
A | B | A | B
--------------------- | -------------------
1 BRAND | LEFTOVER % | 1 BRAND | LEFTOVER
2 X | Y | 2 X | =Vlookup(A2,Sheet2!A:B,False)
3 | | 3 |
Sheet2 | Sheet1
After this you can drag this formula for the entire range. This will automatically make the formula correct for the below cells as well.
Also, if you need to populate any other fields from the Sheet2 then you can also use the vlookup as an array formula like: VLOOKUP(A2,Sheet2!A:B,{1,2,3,4},FALSE)
Enter this as an array formula using Crtl+Shift+Enter
Here {1,2,3,4} stands for the columns to be fetched.
If you want to know more about vlookup then read this article: http://www.exceltrick.com/formulas_macros/vlookup-in-excel

Resources