Sum if cells contain specific text and subtotal [duplicate] - excel

This question already has an answer here:
SUMIF excluding hidden rows. SUBTOTAL? SUMPRODUCT?
(1 answer)
Closed 6 years ago.
Updated:
I've excel 2007 spreadsheet which is look like this
I did all header to filter, So in C column there could be lot of fodder type. I want when i filtered only Corn or Nipiar then show all total quantity only for visible rows.
I tried this code but it return all corn or nipiar quantity but i need only visible rows
For Corn:
=SUMIF(C6:C500,"corn",D6:D500)
For Nipiar:
=SUMIF(C6:C500,"nipiar",D6:D500)
I tried also , it did not work cause i need depend on specific text like corn or nipiar or whatever
=SUBTOTAL(9,D6:D500)

You need to deal with the hidden/visible property of the quantities in column D individually. Use SUMPRODUCT for this style of cyclic processing and OFFSET with ROW to break the D6:D500 range into individual values to be preprocessed by the SUBTOTAL function into invalid hidden values and valid visible ones.
Before filtering:
After filtering column G for Sheep:

Since once filtered for Corn I think you want to add all visible, please try:
=SUBTOTAL(109,D:D)

Related

Indirect index and match problem formula in different named tables

I have a cell where I want to get the tax% based on a criteria
Coming from "Taxes", depends on manufacturer country, year of release and car type
I've tried to use search and index and its not working at all, I need the cell to check values in the manufacturer country, year of release and car type use these inputs go to the Taxes sheet and get the value
Before I start, I should come clean and say I am an evangelist for the OFFSET() function, and a mortal foe of INDIRECT().
Let's assume that the number of vehicle types (TRUCKS, SEDANS, ....) is the same for each country, ie 8. (If its not then that can be worked around with a bit more effort). You could put this number in a cell somewhere and use it when you need the number of types.
Also, let's say the first column in your screenshot is column A. And that the cell A1 contains "China".
Let's say we are looking for the tax rate in 2009, for SEDANS in France.
Function 1:
=MATCH("France",$A:$A,0) will return 14 (if I have counted correctly)
... ie cell A14 contains the word "France".
On the assumption that the years are the same for all countries we can use any of the header rows to find the right column.
Function 2:
=MATCH(2009,$3:$3,0)-1 will return 8 I think.
If your years are just strings of text, then replace 2009 with "2009".
Because your Types are not in the same order in each table (why?) we need an extra step.
Function 3:
=MATCH("SEDANS",OFFSET($A$1,(Result of f1) -1 + 3,0,8,1),0) should return 3.
What is the maths in the OFFSET function? I need to go down (14-1) rows from cell A1 to get to "France". From there I need to go down another 3 rows to get to the first of the list of Types, and there are 8 types to search in. I'm then looking at a range of cells which is 8 rows x 1 column.
Now you can extract your tax rate, using
Function 4:
=INDEX(OFFSET($A$1,(Result of f1) -1+3,1,8,100),(Result of f3),(Result of f2))
(I've put 100 as I don't know how many columns of years you have. You could use something like =COUNTA($3:$3)-1 if there was nothing else in the 3rd row after the last date).
I would put the results of each function in a cell while you test this. Once you are happy that each step is working correctly you can nest all the various functions together, or alternatively just put some extra columns on the right hand side of your results table, which you can Hide if you want to.
EDITED: To add some $ on cell references to lock the "origin" of the data.
If your tax tables are real Tables, each NAME'd with the name of the respective country, you can use something like:
=VLOOKUP(H13,INDIRECT(H12),MATCH(TEXT(H14,"0"),INDIRECT(H12 & "[#Headers]"),0))
where
H12 contains the name of the country
H13 contains the Type of vehicle
H14 contains the Year
eg:
You'll need to adapt this to your real ranges, but this provides an approach.
I'd suggest using dropdown lists (from Data Validation) in H13:H14 in order to avoid typos.
If you want to avoid using Tables and also the volatile functions OFFSET and INDIRECT (because if you have a lot of volatile functions they can impair performance of your worksheet) you can try the non-volatile, but longer and more obscure:
=VLOOKUP($H$13,INDEX($A:$A,MATCH($H$12,$A:$A,0)):INDEX($D:$D,LOOKUP(2,1/($A:$A<>""),ROW($A:$A))),$H$14-2000,FALSE)
In the above, you'll have to make adjustments
Assumptions are:
The country name is above the relevant tax table
Tax table starts in Column A
Change references to Column A if it does not start there.
Change the reference to Column D to the last column of your tax table (or even further if you will be expanding it).
The Year columns are labelled the same for all countries (eg: consecutive years starting at 2002)
$H$14-2000 calculates the column argument for the VLOOKUP function.

Excel multiple criteria by row

I am having trouble with Excel. I have a data set containing bibliography. For each row I have each author from a specific title, separated by columns. I wanted to make an association between authors to see which have publications together and how many times.
Example of data set:
full view
Output wanted:
full view
I have approximately 43 columns by 500 rows. I've already tried COUNTIFS and SUMPRODUCT but both don't give me the output that I want.
Thank you for your help :)
There may be an easier way than this, but with 43 columns (a lot of co-authors?) I can only think of using an array formula, so the method is:-
(1) Get row totals of original data for first author
(2) Get row totals of second author
(3) Multiply them together to get rows (publications) where both authors occur.
(4) Optional - check that each row total is greater than zero -shouldn't be necessary unless author's name is repeated.
(5) Add them all up.
=SUM(--(MMULT(N($A$2:$D$20=G$1),TRANSPOSE(COLUMN($A$1:$D$1))^0)*MMULT(N($A$2:$D$20=$F2),TRANSPOSE(COLUMN($A$1:$D$1))^0)>0))
Must be entered as an array formula using CtrlShiftEnter.
I have just used initials to demonstrate the method.
I have formatted them using "#" to make the zeroes appear as blanks.

Need help on getting specific information from an excel formula

I work for a company that has multiple locations selling auto parts. I'm wanting to look at the 'freshness' of the inventory, but for a specific year range for specific vehicle(s).
The basic formula I'm using is
=COUNTIFS(INVENTORY!$A$2:$A$50000,$B$1,INVENTORY!$I$2:$I$50000,$J$117,INVENTORY!P$2:P$50000,$C$118)
Result is 4
The first argument is looking at the location, the second is looking at the particular vehicle. The third is determining whether the inventory is either 30, 60 or 90 days old, and I'm getting the right information. What I want to know now is, while looking at those 4 vehicles, how many of those are made between the years 2004 to 2010, so the criteria for the 4th argument has a range within it, not one specific year (I know the result should come back as 1 in either the 30, 60 or 60+ cell). On the inventory sheet, the years of the vehicles are in column 'E'. I'm not sure if I need to use imbedded IF statements to specify the year range, or need to rewrite the whole formula. Can anyone give me some advise on how to write the formula to get this info?
You can add two conditions to your COUTINFS on the same E column for the year, i.e.
=COUNTIFS(INVENTORY!A:A,$B$1,INVENTORY!I:I,$J$117,INVENTORY!P:P,$C$118,
INVENTORY!E:E, ">=2004", INVENTORY!E:E, "<=2010")
The second line above shows the additional consitions. If the range of years is dynamically present in cells, say C1 and D1, the criteria should be composed by concatenation, i.e.
=COUNTIFS(INVENTORY!A:A,$B$1,INVENTORY!I:I,$J$117,INVENTORY!P:P,$C$118,
INVENTORY!E:E, ">="&C1, INVENTORY!E:E, "<="&D1)
' ^^^^^^ ^^^^^^

Excel formula to extract multiple matching values [duplicate]

This question already has an answer here:
INDEX and SMALL only returning one result
(1 answer)
Closed 7 years ago.
I'm looking for what I thought would be a pretty straightforward formula to compile a list of names based on a criterion. For example, I would have a list of 50 employee names in column A and then a "Y" or "N" next to each name in column B. I would then like to have another tab on the spreadsheet list the names of everyone with a "Y" value in column B. I dont want empty rows between the names in the list on the new tab (this is why I haven't had success with IF statements). I also would like to avoid manually filtering out blank rows.
Lets say your first sheet is Sheet1
on Sheet 2 on a1 enter:
=IF(ISERROR(INDEX(Sheet1!A:A,MATCH("Y",Sheet1!B:B,0))),"",INDEX(Sheet1!A:A,MATCH("Y",Sheet1!B:B,0)))
On a2 enter:
=IF(ISERROR(INDEX(INDIRECT("Sheet1!A"&MATCH(A1,Sheet1!A:A,0)+1&":A50"),MATCH("Y",INDIRECT("Sheet1!B"&MATCH(A1,Sheet1!A:A,0)+1&":B50"),0))),"",(INDEX(INDIRECT("Sheet1!A"&MATCH(A1,Sheet1!A:A,0)+1&":A50"),MATCH("Y",INDIRECT("Sheet1!B"&MATCH(A1,Sheet1!A:A,0)+1&":B50"),0))))
And just drag the 2nd formula down.
Note that I assumed your first sheet is with 50 Rows as you wrote, Otherwise additional modifications needs to be made.
The formula you are looking for is quite complicated and requires cyclic calculation. For this reason, it is not advisable to use for long lists of several hundred or thousand 'names' but a list of 50 names should pose no discernible difficulties.
With the names in Sheet1's A2:A51, use this formula in the worksheet destined to receive the Y names.
=IFERROR(INDEX(Sheet1!$A$2:$A$51, AGGREGATE(15, 6, ROW($1:$50)/(Sheet1!$B$2:$B$51="Y"), ROW(1:1))), "")
Fill down as necessary. Note that the AGGREGATE¹ function is returning the position within A2:A51 with ROW(1:50).
Retrieving the non Y names should be a simple matter of changing the primary condition to (Sheet1!$B$2:$B$51="N") or (Sheet1!$B$2:$B$51<>"Y").
For pre XL2010 circumstances, this standard formula performs the same filtered retrieval.
=IFERROR(INDEX(Z!$A$2:$A$51, SMALL(INDEX(ROW($1:$50)+(Z!$B$2:$B$51<>"Y")*1E+99, , ), ROW(1:1))), "")
¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions.

Excel index match multiple row results

I'm stuck on an Excel problem and am hoping someone can assist. I read through 10-15 topics that are similar, but I wasn't able to get anything to work. Here is where I'm at...
I have a large data set containing columns for Year, Name, Total 1, Total 2 (and 20+ other columns). The same names appear in multiple rows based on the yearly totals. On a separate sheet, I have another data set containing Name and would like to pull the data from sheet one into columns as shown below.
I have done this in the past using only one year as the initial data set with the following formula:
=INDEX(DATARANGE,MATCH([#Name],DATARANGE[Name],0),MATCH("Total 1",DATARANGE[#Headers],0))
The problem I am having is the result of adding multiple years of data to my 1st data set. Is there a way to match the row based on name and year and then return the results of the appropriate column?
=SUM(($A$2:$A$9=B$16)*($B$2:$B$9=$A17)*($C$2:$C$9))
Enter above in cell B14 as an array formula or below as standard
=SUMPRODUCT(($A$2:$A$9=B$16)*($B$2:$B$9=$A17)*($C$2:$C$9))
You can do the same for total 2 just replace Cs with Ds
And then drag right and down.
Change the first MATCH function to something like this:
=MATCH(1,INDEX(([#Name]=DATARANGE[Name])*([#Year]=DATARANGE[Year]),0),0)
so as part of your whole formula that would be this
=INDEX(DATARANGE,MATCH(1,INDEX(([#Name]=DATARANGE[Name])*([#Year]=DATARANGE[Year]),0),0)
,MATCH("Total 1",DATARANGE[#Headers],0))
Another way you can use for returning numbers only (as here) is like this: (with cell refs for simplicity).
=SUMPRODUCT((A2:A9=2013)*(B2:B9="name x")*(C1:D1="Total 1"),C2:D9)
If the presented data to be indexed is a table then
This
=MATCH(1,INDEX(([#Name]=DATARANGE[Name])*([#Year]=DATARANGE[Year]),0),0)
should be corrected to a proper structured reference of
#[Name]
Also since this is an array formula it may not work with structured references at all. You'd be better served with regular cell references. Also if it is not a table only cell references will work.

Resources