I have the following Excel spreadsheet:
A B c D
1 Products Sales
2 Product A 50 Product A #VALUE!
3 Product A 60 Product B
4 Product A 20 Product C
5 Product B 90
6 Product C 80
7 Product C 50
8 ="" =""
In Column A is a list of products and their corresponding sales are listed in Column B. In Column D I want to show the sum of the sales by using the following formula:
D2 = SUMPRODUCT(($B$2:$B$8)*($A$2:$A$8=C2))
Instead of showing me the result of 130 (B2+B3+B4) I get an #VALUE! error which is caused by the =" " in Row 8.
How can I make this formula work despite the =" " in Row 8.
I tried to go with this way but it still shows an error:
D2 = SUMPRODUCT(($B$2:$B$8)*($A$2:$A$8=C2)*ISNUMBER($A$2:$A$8)*ISNUMBER($B$2:$B$8))
Please keep the following in mind: I cannot switch the SUMPRODUCT formula to a SUMIF(S) formula since my original file is more complex then the simple example above.
Use the 'native' form (i.e. with comma-separated arguments) of SUMPRODUCT, rather than the 'product' form, since text entries passed to the former are ignored.
=SUMPRODUCT($B$2:$B$8,0+($A$2:$A$8=C2))
I am slightly concerned about your statement "I cannot switch the SUMPRODUCT formula to a SUMIF(S) formula since my original file is more complex then the simple example above.". If the example you gave is not representative of your actual set-up, then it may be that a switch to the 'native' form of SUMPRODUCT is not actually possible (one advantage of the 'product' form is that it allows the processing of two-dimensional arrays, something which is not permissible within the 'native' form.)
Regards
Related
I Have this excel table with me, which contains article types and their size against it, I want to check whether for each article type the sizes are sorted in ascending order or not, by adding a column with indicators as SORTED, NOT SORTED, UNIQUE
I want to do it with Excel formula
A B C
1**ARTICLE SIZE STATUS**
2 A 10 SORTED
3 B 11 SORTED
4 A 12 SORTED
5 A 14 NOT SORTED
6 C 11 SORTED
7 D 12 UNIQUE
8 C 13 SORTED
9 A 13 NOT SORTED
10 B 15 NOT SORTED
11 B 14 NOT SORTED
I tried to apply =IF($A2=$A3:$A$11,IF($B2ATTACHED IMAGE OF DATASET
Uses MAXIFS() so you need Microsoft365.
Formula in C2 and copy down:
=IF(COUNTIF($B$2:$B$11;B2)=1;"UNIQUE";IF(OR(MAXIFS($C$1:C1;$B$1:B1;B2)>C2;AND(MAXIFS(C3:$C$11;B3:$B$11;B2)<C2;COUNTIF(B3:$B$11;B2)>0));"NOT SORTED";"SORTED"))
EDIT
here is a solution for none 365 users.
It is an MATRIX-FORMULA, so use CTRL+SHIFT+ENTER to enter the formula:
for C2 use this
=IF(COUNTIF($B$2:$B$11;B2)=1;"UNIQUE";IF(OR(IFERROR(MAX($C$1:C1*($B$1:B1=B2));0)>C2;AND(IFERROR(MAX(C3:$C$11*(B3:$B$11=B2));0)<C2;COUNTIF(B3:$B$11;B2)>0));"NOT SORTED";"SORTED"))
for C3 use this and copy down:
=IF(COUNTIF($B$2:$B$11;B3)=1;"UNIQUE";IF(OR(IFERROR(MAX($C$2:C2*($B$2:B2=B3));0)>C3;AND(IFERROR(MAX(C4:$C$11*(B4:$B$11=B3));0)<C3;COUNTIF(B4:$B$11;B3)>0));"NOT SORTED";"SORTED"))
Such a lookup is now relatively easy with the new XLookup function.
I tried to re-engineer the logic in your data sample, but there must be some typo or thinking error.
Scenario 1: If "sorted" means that the next number can only be 1 larger than the previous number, then A=12 should not be "sorted". The formula is
=IF(XLOOKUP(A2,$A$1:A1,$B$1:B1,IF(COUNTIF(A:A,A2)>1,"sorted","unique"),0,-1)="unique","unique",
IF(XLOOKUP(A2,$A$1:A1,$B$1:B1,"sorted",0,-1)="sorted","sorted",
IF(XLOOKUP(A2,$A$1:A1,$B$1:B1,,0,-1)-B2>1,"sorted","not sorted"
)))
Scenario 2:If, however, "sorted" means that the number in that row is bigger than the last number for this article, then B=15 should be "sorted". The formula is
=IF(XLOOKUP(A2,$A$1:A1,$B$1:B1,IF(COUNTIF(A:A,A2)>1,"sorted","unique"),0,-1)="unique","unique",
IF(XLOOKUP(A2,$A$1:A1,$B$1:B1,"sorted",0,-1)="sorted","sorted",
IF(XLOOKUP(A2,$A$1:A1,$B$1:B1,,0,-1)<B2,"sorted","not sorted"
)))
With the new Let() function, the repeated Xlookups can be avoided.
=LET(
x,XLOOKUP(A2,$A$1:A1,$B$1:B1,IF(COUNTIF(A:A,A2)>1,"sorted","unique"),0,-1),
result,IF(ISTEXT(x),x,IF(x<B2,"sorted","not sorted")),
result)
XLookup is available in Office 365 versions of Excel.
Let is currently in preview and only available in Insider/Beta builds of Office 365.
I am trying to do in Excel what should be done in a database. I have a spreadsheet with raw data and which I am trying to query based on criteria. Given the following example table:
A B C D E F
1 Red up 1 4 dn 5
2 Blu up 5 9
3 Yel dn 1 4
4 Gre dn 5 9
I would like to return the value of column A that meets the criteria of E1 and F1 where E1 is found in column B and F1 is found equal or between the values in columns C and D. In the example, I would like to return "Gre".
I have been pulling my hair out with INDEX and MATCH functions and I can get part of my task done, but have found nothing extensible to solve the total solution.
Thank you in advance for your help!
Please try this...
=IFERROR(INDEX($A$1:$A$4,MATCH(1,INDEX(($B$1:$B$4=$E$1)*($C$1:$C$4<=$F$1)*($D$1:$D$4>=$F$1),),0)),"")
If you don't mind adding headings to your raw data.
You could use this formula:
=DGET($A$1:$D$5,"Field 1",$E$1:$F$2)
A1:D5 being your database.
Field 1 is the field to return values from.
E1:F2 is your criteria (field name and value to look for in that field).
https://support.office.com/en-gb/article/DGET-function-455568bf-4eef-45f7-90f0-ec250d00892e
As noted by #Vityata this won't work for the OP - looking for the value 6 would return a #VALUE error rather than Gre.
A couple of updates would allow it to work:
Updating the formula to: =DGET($A$1:$D$5,"Field 1",$E$1:$G$2)
Updating the table to:
The values in F2 and G2 are calculated as:
="<=" & $H$2 and =">=" & $H$2
This example would then return Yel when 1 is entered in cell H2.
I liked the question, thus I have elaborated a bit on the sktneer's answer.
The reason, it works is because we are looking for truth (a.k.a. 1) in the following formula:
=MATCH(1;
INDEX(($B$1:$B$4=$E$1)*($C$1:$C$4<=$F$1)*($D$1:$D$4>=$F$1););0)
Like this:
Then with an INDIRECT we may achieve the answer:
=INDIRECT(ADDRESSE(I1;1))
If you want it in one formula, it should be like this:
=INDIRECT(ADDRESS(
MATCH(1;INDEX(($B$1:$B$4=$E$1)*($C$1:$C$4<=$F$1)*($D$1:$D$4>=$F$1););0);
1))
I have googled for hours, not being able to find a solution to what I need/want. I have an Excel sheet where I want to sum the values in one column based on the criteria that either one of two columns should have a specific value in it. For instance
A B C
1 4 20 7
2 5 100 3
3 100 21 4
4 15 21 4
5 21 24 8
I want to sum the values in C given that at least one of A and B contains a value of less than or equal to 20. Let us assume that A1:A5 is named A, B1:B5 is named B, and C1:C5 is named C (for simplicity). I have tried:
={SUMPRODUCT(C,((A<=20)+(C<=20)))}
which gives me the rows where both columns match summed twice, and
={SUMPRODUCT(C,((A<=20)*(C<=20)))}
which gives me only the rows where both columns match
So far, I have settled for the solution of adding a column D with the lowest value of A and B, but it bugs me so much that I can't do it with formulas.
Any help would be highly appreciated, so thanks in advance. All I have found when googling is the "multiple criteria for same column" problem.
Thanks. That works. Found another one that works, after I figured out that excel does not treat 1 + 1 = 1 as I learnt in discrete mathematics, but as you say, counts the both the trues. Tried instead with:
{=SUM(IF((A<=20)+(B<=20);C;0))}
But I like yours better.
Your problem that it is "summing twice" in this formula
={SUMPRODUCT(C,((A<=20)+(C<=20)))}
is due to addition turning first TRUE plus the second TRUE into 2. It is not actually summing twice, because for any row, if only one condition is met, it would count that row only once.
The solution is to transform either the 1 or the 2 into a 1, using an IF:
={SUMPRODUCT(C,IF((A<=20)+(C<=20))>0, 1, 0)}
That way, each value in column C would only be counted at max once.
Following this site you could build up your SUMPRODUCT() formula like this:
=SUMPRODUCT(C,SIGN((A<=20)+(C<=20)))
So, instead of a nested IF() you control your or condition with the SIGN()function.
hth
If you plan to use a large set of data then it is best to use the array formula:
{=SUM(IF((A1:A5<=20)+(B1:B5<=20),C1:C5,0))}
Obviously adjust the range to suit the data set, however if the whole of each column is to form part of the formula then you can simply adjust to:
{=SUM(IF((A:A<=20)+(B:B<=20),C:C,0))}
This will perform the calculation on all rows of data within the A, B and C columns. With either example remember to press Ctrl + Shift + Enter in order to trigger the array formula (as opposed to typing the { and }).
I would like to combine two functions (excel 2013).
I have this function:
=SUM(IF(FREQUENCY(IF(H3:H1002="";IF(C3:C1002="PRODUCT";MATCH(B3:B1002;B3:B1002;0)));ROW(B3:B1002)-ROW(B3)+1);1))
..and want to combine with this function:
=SUMIF(C:C;"OTHER PRODUCT";B:B)
ONLY IF the value in row B3:B1002 is between 1-500 (numerical), otherwise count rows separately and use the first function on top above.
Is this possible?
Given comments below I have completely revised my answer. Try this formula
=SUMIFS(B3:B1000;C3:C1000;"OTHER";B3:B1000;"<=500";H3:H1000;"")+SUM(IF(FREQUENCY(IF(H3:H1000="";IF(C3:C1000="OTHER";IF(B3:B1000>500;MATCH(B3:B1000;B3:B1000;0))));ROW(B3:B1000)-ROW(B3)+1);1))
confirmed with CTRL+SHIFT+ENTER
That will sum any numbers <= 500 in column B, for the specified product and where column H is blank, but also add 1 for every distinct text value or number above 500
I am analysing library statistics relating to loans made by particular user categories. The loan data forms the named range LoansToApril2013. Excel 2007 is quite happy for me to use an index range as the sum range in a SUMIF:
=SUMIF(INDEX(LoansToApril2013,0,3),10,INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6))
Here 10 indicates a specific user category, and this sums loans made to that group from three columns. By "index range" I'm referring to the
INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6)
sum_range value.
However, if I switch to using a SUMIFS to add further criteria, Excel returns a #VALUE error if an index range is used. It will only accept a single index.
=SUMIFS(INDEX(LoansToApril2013,0,4),INDEX(LoansToApril2013,0,3),1,INDEX(LoansToApril2013,0,1),"PTFBL")
works fine
=SUMIFS(INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6),INDEX(LoansToApril2013,0,3),1,INDEX(LoansToApril2013,0,1),"PTFBL")
returns #value, and I'm not sure why.
Interestingly,
=SUMIFS(INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,4),INDEX(LoansToApril2013,0,3),1,INDEX(LoansToApril2013,0,1),"PTFBL")
is also accepted and returns the same as the first one with a single index.
I haven't been able to find any documentation or comments relating to this. Does anyone know if there is an alternative structure that would allow SUMIFS to conditionally sum index values from three columns? I'd rather not use three separate formulae and add them together, though it's possible.
The sumifs formula is modelled after an array formula and comparisons in the sumifs need to be the same size, the last one mimics a single column in the LoansToApril2013 array column 4:4 is column 4.
The second to bottom one is 3 columns wide and the comparison columns are 1 column wide causing the error.
sumifs can't do that, but sumproduct can
Example:
X 1 1 1
Y 2 2 2
Z 3 3 3
starting in A1
the formula =SUMPRODUCT((A1:A3="X")*B1:D3) gives the answer 3, and altering the value X in the formula to Y or Z changes the returned value to the appropriate sum of the lines.
Note that this will not work if you have text in the area - it will return #VALUE!
If you can't avoid the text, then you need an array formula. Using the same example, the formula would be =SUM(IF(A1:A3="X",B1:D3)), and to enter it as an array formula, you need to use CTRL+SHIFT+ENTER to enter the formula - you should notice that excel puts { } around the formula. It treats any text as zero, so it will successfully add up the numbers it finds even if you have text in one of the boxes (e.g. change one of the 1's in the example to be blah and the total will be 2 - the formula will add the two remaining 1s in the line)
The two answers above and a bit of searching allowed me to find a formula that worked. I'll put it here for posterity, because questions with no final outcome are a pain for future readers.
=SUMPRODUCT( (INDEX(LoansToApril2013,0,3)=C4) * (INDEX(LoansToApril2013,0,1)="PTFBL") * INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6))
This totals up values in columns 4-6 of the LoansToApril2013 range, where the value in column 3 equals the value in C4 (a.k.a. "the cell to the left of this one with the formula") AND the value in column 1 is "PTFBL".
Despite appearances, it isn't multiplying anything by anything else. I found an explanation on this page, but basically the asterisks are adding criteria to the function. Note that criteria are enclosed in their own brackets, while the range isn't.
If you want to use names ranges you need to use INDIRECT for the Index commands.
I used that formula to check for conditions in two columns, and then SUM the results in a table which has 12 columns for the months (the column is chosen by a helper cell which is 1 to 12 [L4]).
So you can do if:
Dept (1 column name range [C6]) = Sales [D6];
Region (1 column name range [C3]) = USA [D3];
SUM figures in the 12 column monthly named range table [E7] for that 1 single month [L4] for those people/products/line item
Just copy the formula across your report page which has columns 1-12 for the months and you get a monthly summary report with 2 conditions.
=SUMPRODUCT( (INDEX(INDIRECT($C$6),0,1)=$D$6) * (INDEX(INDIRECT($C$3),0,1)=$D$3) * INDEX(INDIRECT($E7),0,L$4))