Excel formula-based lookup for multiple criteria across multiple sheets? - excel

I have a series of tabs formatted uniformly that contain data that I want to consolidate onto one master data sheet. I'd like to do this without indexing/looking up each sheet individually.
I've created a sample to illustrate the challenge I'm having in searching for data across multiple tabs to create a master data dump. Given the 4 worksheets shown below, the Summary tab has pre-filled values and I'm trying to fill in for the values marked with ??? if possible.
John:
| Month 1 | Month 2 | Month 3
---------------------------------------
Sales | 500 | 1000 | 800
Expenses | 200 | 300 | 250
Total | 300 | 700 | 550
Joe:
| Month 1 | Month 2 | Month 3
---------------------------------------
Sales | 400 | 800 | 600
Expenses | 300 | 280 | 225
Total | 100 | 520 | 375
Mary:
| Month 1 | Month 2 | Month 3
---------------------------------------
Sales | 750 | 850 | 900
Expenses | 275 | 325 | 400
Total | 475 | 525 | 500
Summary:
Agent | Period | Sales | Expanses | Total
-------------------------------------------
Joe | Month 1 | ??? | ??? | ???
Joe | Month 2 | ??? | ??? | ???
Joe | Month 3 | ??? | ??? | ???
John | Month 1 | ??? | ??? | ???
John | Month 2 | ??? | ??? | ???
John | Month 3 | ??? | ??? | ???
Mary | Month 1 | ??? | ??? | ???
Mary | Month 2 | ??? | ??? | ???
Mary | Month 3 | ??? | ??? | ???

In your sample, the detail sheet data fits exactly in the summary, except that it is transposed. If this is the case for the actual data as well, you may be best off if you copy each chunk of detail data (3x3 in sample) and then paste special - transpose in succession (in case it helps transpose is a check box which appears on the paste special dialog).

I like Steve Klein's answer for simplicity and ease of understanding. Here's an alternative if you really need it to be dynamic. "Sales", "Expenses", "Month1", "Month2", etc. as well as "Joe", "John" & "Mary", need to be exactly as in the detail sheets and the detail sheet names.
=INDEX(INDIRECT($B2&"!"&"$A$1:$D$6"),MATCH(D$1,INDIRECT($B2&"!a:a"),0),MATCH($C2,INDIRECT($B2&"!3:3"),0))

Related

Excel: How to transform multiple columns with headers into 2 columns, one for the data, one for the header

I have a table of products, with multiple QTYs by month. How do I convert this table into a 2-columns list - one for QTY, one for month.
Source Data:
Product | 2019-06 | 2019-07 | 2019-08 | 2019-09 | 2019-10
----------------------------------------------------------
Apple | 10 | 10 | 20 | 25 | 10
Orange | 50 | 100 | 75 | 50 | 100
Desired Output:
Product | QTY | Date
---------------------
Apple | 10 | 2019-06
Apple | 10 | 2019-07
Apple | 20 | 2019-08
Apple | 25 | 2019-09
Apple | 10 | 2019-10
Orange | 50 | 2019-06
Orange | 100 | 2019-07
Orange | 75 | 2019-08
Orange | 50 | 2019-09
Orange | 100 | 2019-10
Use Power Query a free MS add-in since 2010, and distributed with Excel 2016+ as Get&Transform.
In the Power Query UI, select the first column and then Unpivot other columns. Rename the columns as needed.
Also see my answer to Resorting Table using Array for more details

Adding fields to Pivot Table from another datasource using VBA

I've created Pivot Tables before using VBA but my professor recently gave us a bonus that although is not necessary, is driving me nuts.
Use a VBA Macro to write Region, District, and Store Name to your first report to create a new report
1) My first report looks like this:
Location | Sum of ActNetSales | Sum of PlanNetSales
----------|--------------------|---------------------
1 | $76,170 | $65,172
100 | $163,691 | $140,057
101 | $34,724 | $29,710
104 | $70,501 | $60,322
106 | $113,826 | $97,391
2) Below is the data source for the above report.
Division | Year | Week | Location | SchedDept | PlanNetSales | ActNetSales | AreaCategory
----------|------|------|----------|-----------|--------------|-------------|--------------
5 | 2018 | 10 | 520 | 541 | 1943.2 | 2271.115 | Non-Comm
5 | 2018 | 10 | 520 | 608 | 4378.4 | 5117.255 | Non-Comm
5 | 2018 | 10 | 520 | 1059 | 1044.8 | 1221.11 | Comm
5 | 2018 | 10 | 520 | 1126 | 6308 | 7372.475 | Non-Comm
3) My professor wants me to add the following information to the above table: Region, District and Store Name. However, these 3 fields are from a different data source then the above report. Below is the data source for the 3 fields I've listed.
Division | Location | LocationName | Region | RegionName | District | DistrictName
----------|----------|--------------|--------|------------|----------|--------------
5 | 1 | Location 1 | 3 | Region 3 | 18 | District 18
5 | 4 | Location 4 | 5 | Region 5 | 32 | District 32
5 | 5 | Location 5 | 3 | Region 3 | 19 | District 19
5 | 6 | Location 6 | 5 | Region 5 | 28 | District 28
I've created what he's asking above by joining the 2 tables (created a key by concatenating the foreign keys - location and division: to make a unique key and using a basic index/match ) and just creating a Pivot Table from that but I want to try my best to solve the bonus! Unfortunately, I don't have Power Query so I had to do it this way. I've tried searching up the above and I can't find any good resources. Is there anything you can suggest or just point me in the right direction? Thank you!
Is it cheating to modify your table under (2) to add the columns region, district, and storename using VLOOKUP on the third table? The second table would then have raw data, and extra columns of constructed data, effectively joining it to the third table using the Excel VLOOKUP trick rather than an actual SQL table join.
Then you can just use the expanded, joined table as your one Pivot Table source.
Cheating is legal in love, war, and IT solutions.

Formula to get the month of the last value

I have sales data by customer as follows:
| - | A | B | C | D | E | F | G |
|---|---------------|--------|--------|--------|--------|--------|--------|
| 1 | Customer Name | Jan-18 | Feb-18 | Mar-18 | Apr-18 | May-18 | Jun-18 |
| 2 | Mr.A | 1000 | 500 | 0 | 200 | 0 | 0 |
| 3 | Mr.B | 0 | 300 | 200 | 0 | 0 | 100 |
I need the formula to know the last sales of the respective customer booked (the name of the month)
in this case, Mr. A last order is in Apr-18 while Mr.B is in Jun-18.
I have 2,000 plus customer and sales data since Apr 2016 up to last month, it will be a huge time saving to have a formula to help.
Assuming your 'months' are dates, not Text. Courtesy #barry houdini:
=LOOKUP(2,1/(B2:G2<>0),B$1:G$1)
in Row2 and copied down to suit, formatted mmm-yy.
Ref
An alternative to using LOOKUP() as in this answer, not sure what impact it has performance-wise as both need to create an array but I would take a stab in the dark that this is less performant:
=INDEX($B$1:$G$1,,MAX((B2:G2<>0)*COLUMN(B2:G2)-1)) - Ctrl+Shift+Enter
Ofcourse this could be edited to a dual lookup on the customer too:
=INDEX($B$1:$G$1,,MAX(INDEX(($B$2:$G$3<>0)*COLUMN($B$2:$G$3)-1,MATCH("Mr.B",$A$2:$A$3,0),0)))
This doesn't require the CSE as INDEX() handles the array manipulation

SUMIFS on filtered data?

I am looking for a way to do a SUMIFS that uses a filtered list. I would like to:
Grab all the sales from Sheet "Sales" where Group = "Flowers", AND
Store # on Sheet "Sales" matches the Filtered Store # list on sheet" Report
The following code will work only when there is no filter on the Store #'s:
=SUMIFS(Sales!C:C,Sales!B:B,"=FLOWERS",Sales!A:A,Report!A:A)
Sheet 1 Name = Report
Row (filtered) Store # (A)
====================|==============|
| 21 | 13 |
| 36 | 28 |
| 81 | 75 |
| 84 | 78 |
Sheet 2 Name = Sales
Store # (A) Group (B) Sales (C)
===========|==============|=============|
| 21 | Flowers | $100 |
| 36 | Flowers | $200 |
| 81 | Bread | $500 |
| 1 | Flowers | $600 |
| 3 | Flowers | $100 |
| 36 | Bread | $200 |
| 8 | Bread | $100 |
| 84 | Flowers | $300 |
Is there any way for me to accomplish this? So if when the filtered list changes, the total figure changes, similar to that of a subtotal.
Seems much the easiest way is with a PivotTable: Group (B) for FILTERS, Store # (A) for ROWS and Sum of Sales (C) for VALUES, then filter Group (B) to select 'Flowers` and filter rows to suit.

Count distinct occurrences and averages in a column based on identifiers in another column

In MS Excel, I want to count the number of distinct categories (ignoring a specific item) based on a different column. Also, I want to find the average and the max for the same selection. This is the data:
+--------+-----------+-------+
| Person | idea | score |
+--------+-----------+-------+
| George | vacuum | 9 |
| George | box | 6 |
| George | x | 1 |
| Joe | scoop | 4 |
| Joe | x | 1 |
| Joe | x | 1 |
| Joe | scoop | 4 |
| Joe | gear | 7 |
| Mike | harvester | 10 |
| Mike | gear | 7 |
| Mike | box | 6 |
+--------+-----------+-------+
The result should be the following:
+--------+----------------+------------+-----------+
| Person | distinct ideas | Avg. score | Max score |
+--------+----------------+------------+-----------+
| George | 2 | 5.3 | 9 |
| Joe | 2 | 3.4 | 7 |
| Mike | 3 | 7.7 | 10 |
+--------+----------------+------------+-----------+
Because Joe has two "scoop" and one "gear" idea, and I want to ignore the "x" items.
I reluctantly gave up and did it manually for each person, e.g., this is for the first person:
SUM(IF(FREQUENCY(MATCH(B2:B4,B2:B4,0),MATCH(B2:B4,B2:B4,0))>0,1))-IF(COUNTIF(B2:B4,"x")>0,1,0)
Doesn't Excel have functions to return a range instead of a value? If I could select the range based on the name of the person in the first columns, I could count distinct occurrences or find the average in another column.
Add a 4th column and label it Distinct Ideas
If your table starts in A1, then:
EDIT: Formula changed to exclude "x". Screen shot also changed
D2: =IF(TRIM($B2)="x",0,IF(SUMPRODUCT(($A$2:$A2=A2)*($B$2:$B2=B2))>1,0,1))
and fill down.
Then construct a Pivot table
Person to Row Labels
Distinct Ideas to Values area
score to Values and select to Average
Score to Values area and Select Max
Format as desired. Here is one result:

Resources