Cross referencing Excel worksheets - excel

I'm working with 3 worksheets.
PROJECTS consists of the following:
Project ClientCode Code
------ ---------- ----
Project1 ABC 123
Project2 ABC 456
Project3 DEF 789
INVOICES consists of:
ProjectCode Amount
----------- -----
123 $100
789 $200
123 $50
And CLIENTS consists of:
Code Total
---- -----
ABC [$150]
DEF [$200]
I'm trying to create a formula which will populate the "Total" field on the client sheet by determining which invoices belong to which project belong to which client. I feel like it would be a combination of SUMIF and LOOKUP, but I'm stumped.
EDIT: Revised the above to the format discussed below (swapped Projects column B and C)

Using VLOOKUP and SUMIF in a single cell without any helper column is possible, but you will need to interchange the positions of columns ClientCode and Code in PROJECTS for it to work.
Interchange the column positions as mentioned above (so that ClientCode is before Code), then use:
=SUMIF(INVOICES!A:A, VLOOKUP(CLIENTS!A2, PROJECTS!B:C, 2, 0), INVOICES!B:B)
I'm assuming that row 1 of each worksheet has the column headers. A2 here refers to ABC.
VLOOKUP first looks for the Code of the ClientCode and SUMIF then sums the amounts of matched Code in the INVOICES worksheet.
EDIT: Below should work better since VLOOKUP finds only the first match, which doesn't work here.
=SUM(SUMIF(INVOICES!A:A,IF(CLIENTS!A1=PROJECTS!C:C,PROJECTS!B:B),INVOICES!F:F))
Note that you have to use Ctrl+Shift+Enter to use this formula. After you did it for ABC, you can drag the formula to B. Also note that his formula can take some time to evaluate, and as such, it might be better if you change the ranges to an appropriate range. For example, if INVOICES has only 100 rows, change INVOICES!A:A, INVOICES!B:B to INVOICES!A2:A100, INVOICES!B2:B100, same goes for the other ranges in this formula.

Related

How to use VLOOKUP function in MS Excel

I am very very new to Excel
I have two sheets
Sheet 1
Country PMU Cluster
A Asia Mercury
B Australia Venus
C North America Jupiter
All the countries and continents are unique here
In sheet 2
I have
CountryCode Country PMU Cluster
123 A
234 A
453 B
235 C
1 country can have multiple codes
I have to take the PMU and Cluster and merge it with Sheet 2 , sheet 2 will have an additional column of Country Code.
Any help is very much apprciated.
Replacing my answer per your edits.
I'm just doing this on a single sheet but you can easily adapt by pointing to your other sheet for your lookup array.
Here is the formula for cell G2:
==VLOOKUP($F2,$A:$C,2,FALSE)
Here is the formula for cell H2:
=VLOOKUP($F2,$A:$C,3,FALSE)
Drag your formulas down and you're done. Vlookup formulas are very useful I recommend looking up how they work as someone else could better explain than I. Basically, you are looking up a value (column F) in an array (columns A,B,C) and returning a column index (B = 2, C = 3, etc) for a match. Lastly, you are looking for an approximate (TRUE) or exact (FALSE) match. Almost always use FALSE.
Also, look up cell references and how to lock them (ie, how $ signs rules vary). That way you can easily drag formulas across and keep your lookup value and array the same.

Excel look up value in array, return next value

I would like to look up a value in a range and return the value in the next row, but can't quite figure out how to do this. I especially would like to do this with formulas rather than VBA, and preferably with built-in formulas than custom (VBA) formulas, due to macro security issues.
I'm using Excel 2010. My workbook has two worksheets, "assessment" and "lookup". In lookup, I have lookup tables.
"lookup" looks something like:
Column A Column B Column C
1 Sales Engineering Manufacturing
2 Alice Bobbie Charlie
3 Dawn Edgar Frank
4 George Holly Isabel
In "assessment," I have some some drop downs from which users select one name from each column in "lookup." Based on some other criteria, I then rank these and create a new, sorted list (using INDEX() and MATCH()) that produce the selected name and corresponding column name a new sort order
Column A Column B
10 Engineering Edgar
11 Sales Alice
What I'd like is to return the name from the next row.
Column C
10 Holly
11 Dawn
But I'm having real trouble figuring out how to get there.
Assuming lookups is located at B2:D5 (change as required) and the result data is at F2:H3 (change as required) enter this formula in cell H2 then copy down.
=INDEX(
INDEX($B$2:$D$5,0,MATCH($F2,$B$2:$D$2,0)),
1+MATCH($G2,
INDEX($B$2:$D$5,0,MATCH($F2,$B$2:$D$2,0)),0))

how to find non unique combinations of two variables in Excel?

I have two columns in Excel that identify individual records (ID and code). Some of these may occur multiple times. For some records, the code may be missing. And some IDs belong to multiple codes. I need to find these IDs that have non unique associations with a given code, and show what those are.
Minimal example:
ID code
K151 ABC
K152 BCD
K153 EFG
K154
K151 ABC
K154 HDG
K153 EFF
K151 ABC
K153 EFG
So I need to have a list (possibly with the number of occurences):
ID code freq
153 EFG 2
153 EFF 1
154 1
154 HDG 1
It is fairly easy to do something similar using a Pivot Table, but note that e.g. K151 - ABC occurs 3 times, and it should not be listed, just those IDs that have multiple codes. Also, in the pivot table the codes are collapsed under the ID as parent category and they are not shown side by side.
It is also OK, if the non-uniquely coded IDs are flagged in the original table in a new variable, and then these records can be filtered manually using the flag.
ID code flag
K151 ABC 0
K152 BCD 0
K153 EFG 1
...
K153 EFF 1
...
I need to find a solution in Excel (2013), not VBA or anything else, and ideally the solution should also be compatible with LibreOffice Calc.
The flagging will be simple.
Formula in C2 downwards:
=COUNTIF($A:$A,"="&A2)<>COUNTIFS($A:$A,"="&A2,$B:$B,"="&B2)
Formula in D2 downwards:
=IF(C2,COUNTIFS($A:$A,"="&A2,$B:$B,"="&B2),0)
For OpenOffice we need SUMPRODUCT because COUNTIF will not count if blank.
Formula in C2 downwards:
=COUNTIF($A$1:$A$20,"="&A2)<>SUMPRODUCT(($A$1:$A$20=A2)*($B$1:$B$20=B2))
Formula in D2 downwards:
=IF(C2,SUMPRODUCT(($A$1:$A$20=A2)*($B$1:$B$20=B2)),0)
Copy and paste the first two columns in a different location.
Select the data and Use Remove Duplicates tool in the Data tab.
Start third column and use COUNTIFS for multiple column criteria to get the count of each row.

Automatically working out the average of filtered results

I have a spreadsheet where column P has a score between 1-6
The cell O4 has the following formula: =AVERAGEIFS(P8:P5000,P8:P5000,"<>6",P8:P5000,"<>0")
This formula searches for the average of the score in column P excluding 6, blanks and 0
Column O has staff names e.g John, Mark, Tim.......
What i want to do is for Cell O4 to automatically calculate the average of the figures shown in column P after i have used the filter function to show only results of a selected staff member.
I was hoping excel might be able to do this automatically however cell O4 appears to still be showing the average of the whole column P regardless of whether i have filtered or not.
I was given the formula below on another forum but it seems to be giving slightly wrong results albeit only by a small amount but i need to have the results exact if possible. Any help appreciated.
=SUMPRODUCT(1-ISNUMBER(MATCH(P8:P100,{0,6},0)),SUBTOTAL(9,OFFSET(P8,ROW(P8:P100)-ROW(P8),0,1)))/SUMPRODUCT(1-ISNUMBER(MATCH(P8:P100,{0,6},0)),SUBTOTAL(2,OFFSET(P8,ROW(P8:P100)-ROW(P8),0,1)))
Maybe
{=AVERAGE(IF((P8:P5000<>6)*(P8:P5000<>0)*SUBTOTAL(103,INDIRECT("O"&ROW(8:5000))),P8:P5000))}
will do what you want. Assuming the Filter is on column O.
The 103 in SUBTOTAL will also exclude if rows are manually hidden. If this ist unwanted and it should only exclude hidden rows, if filtered, then use 3 instead.
This is an array formula. Input it into the cell without the curly brackets and then press [Ctrl]+[Shift]+[Enter] to create the array formula.
I would create a separate table in a new sheet with all unique staff members and then perform the calculation. This way, you can quickly compare values for all staff just by scanning the table instead of having to constantly update the filter to see the values for potentially dozens or hundreds of staff. You would add the staff name range and criteria to your AVERAGEIFS formula.
For your example:
Sheet 2
A B
--- ---
1 | Staff Average
2 | Bob =AVERAGEIFS(Sheet1!$P$8:$P$5000,Sheet1!$O$8:$O$5000,A2,Sheet1!$P$8:$P$5000,"<>6",Sheet1!$P$8:$P$5000,"<>0")
3 | Mary =AVERAGEIFS(Sheet1!$P$8:$P$5000,Sheet1!$O$8:$O$5000,A3,Sheet1!$P$8:$P$5000,"<>6",Sheet1!$P$8:$P$5000,"<>0")
4 | Joe =AVERAGEIFS(Sheet1!$P$8:$P$5000,Sheet1!$O$8:$O$5000,A4,Sheet1!$P$8:$P$5000,"<>6",Sheet1!$P$8:$P$5000,"<>0")

Formula: Count text instance within table range

I want to find the instance of a text within a set range.
The following formula will work in general and produce the following info:
=COUNTIFS($B$2:$B2;$B2)
Helper Name
1 Bob
2 Bob
1 John
2 John
3 John
However, with this formula within a Table and insert data into a new row, you get this at the second instance of John:
=COUNTIFS($B$2:$B6;$B5)
Help Name
1 Bob
2 Bob
1 John
3 John
3 John
While the second instance of John should be:
=COUNTIFS($B$2:$B5;$B5)
Since a table will automatically fill in the formula when adding another row, is there a different way to make this formula or an option to make this work?
Sadly, the following code won't work:
=COUNTIFS($B$2:$B&Row(B5);$B5)
Thanks for any support!
This is a known problem with tables, new rows and auto-filled formulas that use conventional cell references. If you maintain the table method of cell addressing, you can reshape the range parameter of COUNTIF with OFFSET and use a table cell reference for the adjoining cell in the Name column.
    
The formula in the first Helper column cell below the header is,
=COUNTIF(OFFSET([Name],0,0,ROW(1:1),1),[#Name])
OFFSET is another volatile function (like INDIRECT) that recalculates on any calculation cycle; not just ones where the values that affect its outcome change. If you have a large amount of data, calculation lag will quickly become annoying.
More on this at Use structured references in Excel table formulas

Resources