I want to use sumproduct on two different tables based on 3rd Table - excel

I'm a Boy Scout Assistant Scout Master and was asked to help with a fundraiser so I'm trying to put together a Excel sheet. I would like to use sumproduct to pull together the totals I need from two tables. My result would be in B3 in referenced pic.
Math:
(C7 * B18) + (C14 * B19)
or
(.19672 * 300)+(1 * 200)
Result of 259.02
Need
Table 2 Dist Hours
Table 3 Total
From
Table 1 Name = $A$3
Table 1 Name = Table 2 Name
Table 2 ID = Table 3 ID
I hope someone can help our Boy Scout Troop (me)

Try the following formula, which needs to be confirmed with CONTROL+SHIFT+ENTER, not just ENTER...
=SUM(IF(B7:B14=A3,SUMIF(A18:A19,A7:A14,B18:B19)*(C7:C14)))
Adjust the ranges accordingly.

For a finite (and static) number of entries in table 3 this method of stacking error controlled lookups should produce the correct result for any name put into table 1.
=IFERROR(INDEX(C7:C14, AGGREGATE(15, 7, ROW($1:$8)/((A7:A14=A18)*(B7:B14=A3)), 1))*B18, 0)+
IFERROR(INDEX(C7:C14, AGGREGATE(15, 7, ROW($1:$8)/((A7:A14=A19)*(B7:B14=A3)), 1))*B19, 0)

Related

Excel - Lookup date in matrix and return column heading

I have a matrix between Products and Enablers, where the intersection between the two represents a point in time.
Product list
Enabler 1
Enabler 2
Enabler 3
Product 1
10-Oct
11-Oct
20-Oct
Product 2
20-Nov
25-Nov
01-Dec
Product 3
10-Oct
21-Oct
25-Oct
I need to turn this into a 'timeline' view so visually there are two ways to see the data, where the dates are across the top and based on the timing in the first table, it returns the corresponding 'Enabler' at the correct date...something like
Product list
10-Oct
11-Oct
12-Oct
Product 1
Enabler 1
Enabler 2
Product 2
Product 3
Enabler 1
Does anyone have any ideas how I'd do this? I think it requires an INDEX MATCH array formula as it needs to look across the matrix to find the date in that row, then return what is in the header column...but this isn't my area of expertise and I just can't seem to figure out how to make it work.
One approach might be to return this as an array. You could do:
=IF( ( Table1[[Enabler 1]:[Enabler 3]] = B7:D7 ) * ( Table1[Product list] = A8:A10),
Table1[[#Headers],[Enabler 1]:[Enabler 3]],
"" )
where Table1 is an Excel Table that holds your Product List and Enablers as columns (as shown in your first table); A8:A10 is the list of products in your second table; and B7:D7 is the list of dates in your second table shown as column headers. The formula would be placed in the upper left cell of your second table - in my example, B8 as shown here:
The result will spill into the second table.
If you wanted your second table to be an Excel Table, the approach
would be different as arrays cannot spill into Excel Tables.

Excel - SUBTOTAL but only where particular criteria is met (SUMIF/AVERAGEIF)

EDIT: The document is set up like a series of dashboards. Some if the data linked to the many graphs is in pivot tables and some just regular tables. Because there are so many graphs, I use some user selection buttons and fields to change what data is shown in these graphs.
Some users open the file in office 2016.
All solutions I found were either limited to 365 or involved creating new data tables or columns which I was trying to avoid as it would mean a fair bit of rework. I instead just used a set of nested IFS and will eventually look at changing these particular pivots to regular tables with index lookups to enable the actual data to be in multiple columns.
I currently use a SUBTOTAL function to either sum, count or average a bunch of cells in a range. I was previously manually filtering the range so I was only totaling the rows I wanted, however the need has arisen to be able to look at several criteria at once.
i.e in the example below, I was previously manually filtering range to only include "Apple" but now I need to be able to total "Apple", "Orange", "Banana" separately, at the same time.
The subtotal fields are used in graphs and I have a cell (F5) that houses a number corresponding to either SUM, COUNT or Average (9, 2 or 1) to use in the subtotal formulas in the "Summary table" which is linked to other functionality within the workbook and I need to still be able to retain that functionality.
Example of how my sheet is setup:
Raw Data
Product Type
Sales QTY
Date
Apple
4
1/9/21
Orange
3
6/9/21
Banana
2
10/9/21
Apple
6
14/9/21
Orange
6
20/9/21
Apple
5
29/9/21
The Criteria I want to match is in Column 1 (Product Type) of the summary table.
Basically, I then want to be able to end up with the ability to display the data either as Totals:
$F$5 = 9
for each line: SUBTOTAL($F$5,SalesQTY)
Summary Table
Product Type
Result (Sales Per Month)
Apple
15
Orange
9
Banana
2
Or as Averages:
$F$5 = 1
for each line: SUBTOTAL($F$5,SalesQTY)
Product Type
Result (Average QTY per Sale)
Apple
5
Orange
4.5
Banana
2
Or as a Count:
$F$5 = 2
for each line: SUBTOTAL($F$5,SalesQTY)
Product Type
Result (# Sales Transactions)
Apple
2
Orange
2
Banana
1
Is there some way I can combine SUMIF and also SUBTOTAL but also be able to retain the ability to flick between average, sum and count?
Here is a formula to create a dynamic summary table in excel 365. If you have any earlier version of excel, the formula would be different and rows would have to be manually added or removed. I'm assuming your table is called Data_Table.
=LET(
Column_Product, Data_Table[Product Type],
Column_QTY, Data_Table[Estimated],
Column_Date, Data_Table[Date]
Column_Key, Column_Product,
Column_Filter1, Column_QTY,
Column_Filter2, Column_Date,
List_Filter1, UNIQUE(Column_Product),
List_Filter2, 1,
Categories, SORT(UNIQUE(Column_Key)),
Array_BoolKey, (TRANSPOSE(Column_Key)=Categories)+0,
Mask1, TRANSPOSE(ISNUMBER(XMATCH(Column_Filter1,List_Filter1))),
Mask2, TRANSPOSE(Column_Filter2>List_Filter2),
Array_BoolMasked, Array_BoolKey*Mask1*Mask2,
Masked_QTY, IFERROR(Array_BoolMasked*TRANSPOSE(Column_QTY),0),
Masked_Date, IFERROR(Array_BoolMasked*TRANSPOSE(Column_Date),0),
Array_Ones, SEQUENCE(COLUMNS(Array_BoolMasked),1,1,0),
Months, DATEDIF(MIN(Column_Date),MAX(Column_Date),"M"),
Body_Count, MMULT(Array_BoolMasked, Array_Ones),
Body_Sum_QTY, MMULT(Masked_FtModeled, Array_Ones),
Body_Average_PerSale, Body_Sum_QTY/Body_Count,
Body_Sum_QTY_PerMo, MMULT(Masked_FtModeled, Array_Ones)/Months,
Total_Count, IFERROR(SUM(Body_Count_Lines),"-"),
Total_QTY_PerMo, IFERROR(SUM(Body_Sum_QTY)/Months,"-"),
Total_Average_PerSale, IFERROR(SUM(Body_Sum_QTY)/Total_Count,"-"),
Array_Seq, {1,2,3,4,5},
Array_Header, CHOOSE(Array_Seq, "Product Type", "Sales Per Month", "Average QTY per Sale", "# Sales Transactions"),
Array_Body, CHOOSE(Array_Seq, Categories, Body_Sum_QTY_PerMo, Body_Average_PerSale, Body_Count),
Array_Total, CHOOSE(Array_Seq, "Total", Total_QTY_PerMo, Total_Average_PerSale, Total_Count),
Range1,Array_Header,
Range2,Array_Body,
Range3,Array_Total,
Rows1,ROWS(Range1), Rows2,ROWS(Range2), Rows3,ROWS(Range3), Cols1,COLUMNS(Range1),
RowIndex, SEQUENCE(Rows1 + Rows2 + Rows3), ColIndex,SEQUENCE(1, Cols1),
RangeTable,IF(
RowIndex<=Rows1,
INDEX(Range1,RowIndex,ColIndex),
IF(RowIndex<=Rows1+Rows2,
INDEX(Range2,RowIndex-Rows1,ColIndex),
INDEX(Range3,RowIndex-Rows1-Rows2,ColIndex)
)),
Return, RangeTable,
Return
)
I wrote this generically so you could add filters for only certain products, or minimum quantity, or a date range, or other criteria. Above, I set up the filter to pass everything.
Solution Used:
To avoid having to rework the many other tables in the sheet that rely on this field and also as some user open this file with older (non-365) versions of excel, I opted for a series of nested IF (CountIF, SumIF, AverageIF) statements instead.

How to count the values in ranges in Excel

I have two columns as shown below. Group values is 0,1,2,3,4 and scores is from 0 to 80. I want to count how many 0s (1s, 2s, 3s, 4s) are present for scores between 0 and 10; 10 and 20; 20 and 30 etc.
I am thinking to use Excel pivot table. But I am stuck - how could I achieve this?
Group scores
1 8.56163
2 34.3649
2 12.2291
0 8.75357
2 8.75967
2 5.87806
0 9.33751
2 32.0303
0 43.5567
2 11.1044
2 24.9266
1 18.9314
-------- result should look like below --------
scores group count
0-10 0 2
0-10 1 1
0-10 2 2
0-10 3 0
0-10 4 0
10-20 0 0
10-20 1 1
10-20 2 2
...
------ PS I have solved this problem using matlab. But it would be nice to see someone do it in Excel.
---------------- thanks for all the anwers. I really appreciate it. I have accepted the 1st answer.
I apologize for my previous answer. You can do binning with PivotTable.
select your whole two columns (A1:B13), insert PivotTable
under rows, put your "Group"
under columns, put your "scores"
under values, put your "Group"
click that last one ("Group" within the values quadrant) and change it to count, not sum
intermediate result:
Now in the resulting pivot table, right click on a colum and select "Group and show detail". You can configure your bins there.
Result:
One option is to use a pivot table, but another option is to use COUNTIFS, e.g.:
=COUNTIFS($A$2:$A$13,"="&$F2,$B$2:$B$13,">="&D2,$B$2:$B$13,"<="&E2)
In practice:
You could just use simple countif formulas:
Type out first criteria into cells. D1 = 0, E1 = 1, F1 = 2 etc.
Now you can just say =COUNTIF($A$2:$A$13,D1) and just drag that out.
The other column would require countifs.
Lets say D3 is blank E3 = ">10", F3 = ">20", etc.
Now D4 = "<=10", E4 = "<=20", F4 = "<=30", etc.
Now you can use =COUNTIF($B$2:$B$13,D4) for your first criteria and =COUNTIFS($B$2:$B$13,E4,$B$2:$B$13,E3) for the next criteria and just drag that out.
Hope this helps, good luck!
Please try:
This uses Grouping (by decade) for the Row labels.
To Group, right-click on one of the entries under Row Labels and Group..., then select enter Starting at:, Ending at: and By: to suit:

Excel: Return a single value based on two references

I have two values that a person would enter information for in column B:
Spreadsheet Name: Info
A B
1 Level 2
2 Class Class 2
In a second spreadsheet within the Workbook, i have a data spreadsheet with various tables.
So when a person enters information in !InfoB2 data validation drop down, it would return the name of the table the formula should use to search for the value in the Data table that's level is related to !InfoB2.
Spreadsheet Name: Data
Table Name: Class 1
A B
1 Level BAB
2 --------------------
3 1 8
4 2 3
Table Name: Class 2
A B
1 Level BAB
2 --------------------
3 1 2
4 2 7
So when someone enters Level: 2, and Class2, i would like it to return the value in the BAB column, how can i do this?
Edit
As ghetto as this is, it feels like it's on the right track, however it's returning #VALUE!
VLOOKUP(B1,VLOOKUP(B2,Class,2,FALSE),2,FALSE)
Table Class
Table Name: Class
A B
1 Class Name Table Name
2 Class 1 Class1Table
3 Class 2 Class2Table
You could try the following formula:
=INDEX(INDIRECT(B2&"[#All]"), MATCH(B1,INDIRECT(B2&"[[#All],[Level]]"),0), 2)
This takes the value of B2 (Class2 note I removed the space since table names can't contain spaces) and concatenates it with [#All] so you get: Class2[#All] (this is the table reference). INDIRECT converts the text into a valid range.
INDIRECT(B2&"[[#All],[Level]]") similarly gives the range Class2[[#All],[Level]].
MATCH(B1,Class2[[#All],[Level]],0) gives the row number in which the value in B1 is found (i.e. gives the row in which 2 is found, meaning the result is 4)
=INDEX(Class2[#All], 4, 2) then returns the value from range Class2[#All] in the 4th row and 2nd column.
If I understand correctly you will want to use INDIRECT and/or the structured reference syntax for this one.
I don't have access to Excel at the moment so I can't check to see if this would work. I'll update this answer once I try some stuff out.

Excel: filter table rows by specified column value

I have a table with first column as primary key. Ex:
id value1 value2
1 10 5
2 2 3
3 12 5
..
I also have a second list of id's I want to select, which can have repeated ids. Ex:
selectId
1
2
2
2
5
10
..
How can I "merge" the two tables (something like INNER JOIN) to obtain:
id value1 value2
1 10 5
2 2 3
2 2 3
2 2 3
5 99 99
10 22 22
..
I tried using 'Microsoft Query' from Data > Extern Data to join the two tables. The problem is that it seems it cannot handle tables with more than 256 columns.
Thanks
UPDATE:
Thanks, VLOOKUP works as intended.
However one problem is that if the row was found but that corresponding column was blank, this function returns 0 (where I expected it to return an empty cell), and since zero is a valid value, I have no way to differentiate between the two (blank and zero)?
Any help is appreciated..
If this is Excel -like the title says- just use vlookups.
Not very relational, but that's the Excel way.
Using the VLOOKUP function would get you the data in the layout you require.
If you are using Tables in Excel 2007, the formula would look like this based on the example below.
in cell B8
=VLOOKUP([selectId],Table1,2,FALSE)
in cell C8
=VLOOKUP([selectId],Table1,3,FALSE)
Lookup screenshot http://img208.imageshack.us/img208/1/lookupz.png
It is not clear where you store your data, but it looks like you have this problem, described on Microsoft site:
http://support.microsoft.com/kb/272729

Resources