Excel formula How to get data count from another sheet - excel

On C123 =COUNTIFS(Data!A:A,A123,Data!E:E,Data!G:G,B123,Data!Q:Q,"mobilepod")
its giving me Error, I know I'm missing criteria2 but isn't that an optional?
I have also tried
=COUNTIFS(Data!A:A,A123,Data!E:E,"",Data!G:G,B123,Data!Q:Q,"mobilepod")
No Errors no result
Data Sheet

To use an OR logic in one of the criteria for your COUNTIFS function, put the multiple ctrieria values in as an array of constants and wrap the whole thing in a SUM function.
=SUM(COUNTIFS(data!A:A, A123, data!E:E, {"DIST","DIST 2"}, data!G:G, B123, data!Q:Q, "mobilepod"))

Related

Syntax for Nested Excel Formula - SUMIF Where the Sum Range is a VLOOKUP Which has a Concatenation of Text and Cell Values to Makeup a Sheet Reference

I have a interesting puzzle going on which I believe is a syntax issue that has to do with the nesting of the formula in question. The reason I'm using such a funky formula is probably longwinded to the point of not being interesting, and certainly not useful to solving the issue I'm having. It would be possible to solve my issue without this formula but it would require a VBA project which isn't ideal for this use case. The formula is as follows:
=SUMIF('Sheet1'!$BR:$BR,'Sheet2'!$C19,CONCAT("'Sheet1'!",VLOOKUP(CONCAT($B$1," ",F$5),'Sheet3'!$J:$P,7,FALSE)))
Pulling the full formula apart, I have two formulas that work as expected:
Piece One: =SUMIF('Sheet1'!$BR:$BR,'Sheet2'!$C19,'Sheet1!'$AV:$AV)
Piece Two: =CONCAT("'Sheet1'!",VLOOKUP(CONCAT($B$1," ",F$5),'Sheet3'!$J:$P,7,FALSE))
Piece Two returns a value of 'Sheet1'!AV:AV and Piece One returns a value of 1,000,000 which is the correct SUMIF for the criteria I've set up in the formula. I've tried all sorts of combinations of ( and ) but continue to have Excel give me the message of either Your formula is missing a open or close parenthesis or Did you mean for this to be a formula? When starting a cell with a = or -.....
I'm trying to get the nested formula to resolve the "Part Two" first, so that when the entire nested formula evaluates it would solve "Part Two" which would leave me with an identical formula to "Part One" which would result in the 1,000,000 answer.
What am I missing here? Thanks in advance - this one's got me stumped!
Excel will not by default interpret your string as a range reference. You need to pass it to INDIRECT so as to be interpreted as such:
=SUMIF(
Sheet1!$BR:$BR,
Sheet2!$C19,
INDIRECT(
CONCAT("'Sheet1'!", VLOOKUP(CONCAT($B$1, " ", F$5), Sheet3!$J:$P, 7, FALSE))
)
)
Piece Two returns a value of 'Sheet1'!$AV:$AV
Piece Two in this case returns a string value, that happens to say 'Sheet1'!$AV:$AV. What you need piece two to return is not a text string, but a reference (or 'link') to the range on the sheet that is called 'Sheet1'!$AV:$AV.
To convert a string to a range reference you use the INDIRECT() function.
So your new formula is
SUMIF('Sheet1'!$BR:$BR,'Sheet2'!$C19,INDIRECT(CONCAT("'Sheet1'!",VLOOKUP(CONCAT($B$1," ",F$5),'Sheet3'!$J:$P,7,FALSE))))

Multiple Indirects with named range

I'm trying to write a formula using SUMPRODUCT, SUMIF, INDIRECT and a named range. My formula is:
=SUMPRODUCT(SUMIF(INDIRECT("'"&INDIRECT("EightiesNames")&"'!G8:HI8"),$A$2,INDEX(INDIRECT("'"&INDIRECT("EightiesNames")&"'!G9:HI300"),MATCH($A$1,INDIRECT("'"&INDIRECT("EightiesNames")&"'!E9:E300"),0),0)))
The formula goes through every worksheet in the named range and does a lookup to both the columns (looking up $A$2 in G8:HI8. note that $A$2 may occur multiple times in one worksheet) and rows (looking up $A$1 to E9:E300) before summing together all the return values with SUMIF/SUMPRODUCT.
The formula was inspired by the below simplified version but with SUMPRODUCT and INDIRECT layered in to allow it to perform the same function across multiple tabs.
=SUMIF(G8:HI8, $A$2, INDEX(G9:HI300, MATCH($A$1, E9:E300,0), 0))
See below for a more detailed description of the workbook.
Worksheets:
Sheet1 - houses a named range in cells B2:B7 {Name1, Name2, Name3, Name4, Name5, Name6}. The named range is called "EightiesNames"
Name1 - where the formula is located. The formula references worksheets Name1, Name2, Name3, Name4, Name5, Name6, basically all the worksheets in the named range.
There are three occurrences of "INDIRECT("'"&INDIRECT("EightiesNames")" - after the SUMIF, one after INDEX and after the MATCH. The first occurrence of the two INDIRECTs, works the way I want it to (when I evaluate the formula). It expands the INDIRECT("EightiesNames") into an array {"Name1";"Name2";"Name3";"Name4";"Name5";"Name6"}. The formula then proceeds to tack on the range "'!G8:HI8" after each "Name" - "'Name1'!G8:HI8";...;"'Name6'!G8:HI8".
However, for the INDIRECTs that occur after the INDEX and the MATCH, it does not return an array like the first one. On my computer, it returns "Name2" (returns "Name1" on my friend's), not sure why its different and why it returns those values instead of the entire array.
I'm not really sure how to fix this as the three INDIRECT formulas are identical but do not produce the same result. I also know INDIRECT formulas take up a lot of processing power so I'll gladly take alternatives. Any help/insight would be greatly appreciated! Thanks!
While a single formula solution is possible, it would be very complex, inefficient, and not robust at all. For this reason, I would suggest that you use a regular SUMIF formula for each worksheet, where it would be placed in the same cell for each of your worksheets, let's say B1, and then you could simply use SUM to get your total, for example =SUM('Sheet1:Sheet5'!B1).
However, if you would like to try a single formula solution, try the following formula that needs to be confirmed with CONTROL+SHIFT+ENTER.
Note that I have assumed that G8:HI8 and E9:E300 for each of your worksheets contain text values. If G8:HI8 contains numerical values, replace...
T(OFFSET(INDIRECT("'"&EightiesNames&"'!G8:HI8"),,COLUMN(INDIRECT("G8:HI8"))-7,,1))=$A$2
with
N(OFFSET(INDIRECT("'"&EightiesNames&"'!G8:HI8"),,COLUMN(INDIRECT("G8:HI8"))-7,,1))=$A$2
Also, if E9:E300 contains numerical values, replace...
T(OFFSET(INDIRECT("'"&TRANSPOSE(EightiesNames)&"'!E9:E300"),ROW(INDIRECT("9:300"))-9,0,1))=$A$1
with
N(OFFSET(INDIRECT("'"&TRANSPOSE(EightiesNames)&"'!E9:E300"),ROW(INDIRECT("9:300"))-9,0,1))=$A$1
Here's the formula...
=SUM(IF(T(OFFSET(INDIRECT("'"&EightiesNames&"'!G8:HI8"),,COLUMN(INDIRECT("G8:HI8"))-7,,1))=$A$2,N(OFFSET(INDIRECT("'"&EightiesNames&"'!G9:HI9"),TRANSPOSE(MMULT(TRANSPOSE(ROW(INDIRECT("9:300")))^0,IF(T(OFFSET(INDIRECT("'"&TRANSPOSE(EightiesNames)&"'!E9:E300"),ROW(INDIRECT("9:300"))-9,0,1))=$A$1,ROW(INDIRECT("9:300"))-9,0))),COLUMN(INDIRECT("G9:HI9"))-7,,1)),0))
Hope this helps!

Excel Match function as array formula serching multiple colums

I've got some problem with this function. I've Tried to find position some cell on the list consisted of two columns. My formula MATCH(A1;D1:E10;0) gives me an #N/D error, but when I change formula for each separate column like e.g. MATCH(A1;D1:D10;0) it works. Is three possibility to do this simultanously for both colums. Maybe some array formula?
Match will not work with 2 dimensional ranges.
You can use AGGREGATE to return the correct ROW:
=AGGREGATE(15,6,ROW(D1:E10)/(D1:E10 = A1),1)

INDEX/MATCH with 4 columns

I have an Excel file with 2 sheets - one sheet contains my items, prices, codes, etc. and the other sheet is for cross-matching with competitors.
I've included an Excel file and image below.
I want to be able to generate my code automatically when manually entering any of my competitor's codes. I was able to do INDEX/MATCH but I was only able to match with one column (I'm assuming they're all in one sheet to make it easier). Here is my formula:
=INDEX(C:C,MATCH(K2,E:E,0)
So this is looking only in E:E, when I tried to enter a different column such as C:C or D:D it returns an error.
I tried to do the MATCH as C:G but it gave an error right away.
The reason why match gave you error is because it's looking for an array and you put in multiple columns.
There is definitely a more elegant way to do this but this is the first one that I came up with.
=IFERROR(INDEX(B:B,MATCH(K2,C:C,0)),IFERROR(INDEX(B:B,MATCH(K2,D:D,0)),IFERROR(INDEX(B:B,MATCH(K2,E:E,0)),IFERROR(INDEX(B:B,MATCH(K2,F:F,0)),IFERROR(INDEX(B:B,MATCH(K2,G:G,0)),"")))))
Index/Match Combination
Please try this formula:
{=INDEX($B$2:$B$5,MATCH(1,(K2=$C$2:$C$5)+(K2=$D$2:$D$5)+(K2=$E$2:$E$5)+(K2=$F$2:$F$5)+(K2=$G$2:$G$5),0))}
Instruction: Paste the formula {without the curly brackets} to the formula bar and hit CTRL+SHIFT+ENTER while the cell is still active. This will create an array formula. Hence, the curly brackets. Please take note though that manually entering the curly brackets will not work.
Description:
The INDEX function returns a value or the reference to a value from within a table or range.1
The MATCH function searches for a specified item in a range of cells, and then returns the relative position of that item in the range.2
Syntax:
The INDEX function has two forms—Array and Reference form. We're going use the Reference form in this case.
INDEX(reference, row_num, [column_num], [area_num])1
MATCH(lookup_value, lookup_array, [match_type])2
Explanation:
To simplify, we're going to use this form:
INDEX(reference, MATCH(lookup_value, lookup_array, [match_type]))
The INDEX function returns a value from the reference My code column (B1:B5) based on the row_num argument, which serves as an index number to point to the right cell, and we're going to do that by substituting row_num with MATCH function.
MATCH function, on the other hand, returns the relative position of a value in competitorn column that matches the value in individual cells of the competitor code column.
To make it work with multiple lookup range, we're going to create arrays of boolean values (TRUE/FALSE, aka logical values) by comparing values from individual cells in competitor code column with values in individual competitorn columns. Now, we convert these boolean values into numerical values by performing a mathematical operation that does not alter its implied value (i.e. TRUE=1, FALSE=0). We're going to add these values directly to make it simple. The resulting array have four index with two possible values: 1 or 0. Since each item in MATCH's lookup_array is unique, then there can be only one TRUE or 1. The rest are FALSE or 0's. So, with that knowledge, we're going to use it as our lookup_value.
Let's dissect the formula:
=INDEX(B2:B5,MATCH(1,(K2=C2:C5)+(K2=D2:D5)+(K2=E2:E5)+(K2=F2:F5)+(K2=G2:G5),0))
My code 2 = INDEX({"My code 1";"My code 2";"My code 3";"My code 4"},MATCH)
My code 2 = INDEX({"My code 1";"My code 2";"My code 3";"My code 4"},(2))
2 = MATCH(1,(K2=C2:C5)+(K2=D2:D5)+(K2=E2:E5)+(K2=F2:F5)+(K2=G2:G5),0)
2 =MATCH(1,
{FALSE;FALSE;FALSE;FALSE}+
{FALSE;FALSE;FALSE;FALSE}+
{FALSE;FALSE;FALSE;FALSE}+
{FALSE;FALSE;FALSE;FALSE}+
{FALSE;TRUE;FALSE;FALSE},0))
OR
=MATCH(1,
{0;0;0;0}+
{0;0;0;0}+
{0;0;0;0}+
{0;0;0;0}+
{0;1;0;0},0))
=========
{0;1;0;0},0))
2 = MATCH(1,{0;1;0;0},0))
I hope this answer is helpful.
References and links:
INDEX function
MATCH function
Create an array formula

Combine Vlookups

I'm trying to combine two vlookup statements. Here is what I have:
=VLOOKUP(C2,'Purchase Order Browse'!$Q$4:$R$65,2)
What I want it to do if it doesn't find anything above is to then do a vlookup on this data set
=VLOOKUP(C2,'Work Order Browse'!M4:N123,2)
How do I combine the two to work together?
If a VLOOKUP does not find a match, it should return #N/A, so you could add it into an IF statement.
=IF(ISNA(VLOOKUP(C2,'Purchase Order Browse'!$Q$4:$R$65,2)), VLOOKUP(C2,'Work Order Browse'!M4:N123,2), VLOOKUP(C2,'Purchase Order Browse'!$Q$4:$R$65,2))
Update for Excel 2007+
As pointed out by barry houdini, Excel 2007 and later supports an IFERROR function that takes two params IFERROR(value, value_if_error):
IFERROR function returns a value you specify if a formula evaluates to an error; otherwise, returns the result of the formula.
=IFERROR(VLOOKUP(C2,'Purchase Order Browse'!$Q$4:$R$65,2), VLOOKUP(C2,'Work Order Browse'!M4:N123,2))

Resources