Excel Sumif with number - excel

=SUMIF(A1:A14, "102000*", B1:B14)
Why it cannot filter the value starts with 10200?

An array (CSE) formula solves the issue:
How it works:
Suppose you want to add numbers like 1020001, then enter it as criteria in cell D74, and use this formula.
{=SUM((B74:B82)*(--(A74:A82=D74)))}
If you have more criteria, like I've shown in D74 & in E74, then use this one in C74.
{=SUM((B74:B82)*(--(A74:A82=D74)+(--(A74:A82=E74))))}
N.B.
Finish formula with Ctrl+Shift+Enter.
You may adjust cell references in the formula as needed.

You are better off creating a new column using the formula
left(a1,5)
Then base the sumif off that new column.

If you want to count the number of occurences, you can use
=SUMPRODUCT(--(--LEFT(A1:A7,5)=10200))
and if you actually want to sum values, use
=SUMPRODUCT(--(--LEFT(A1:A7,5)=10200)*(B1:B7))

Related

How to use SUMIF formula over jagged sum range

I have problem where the cells I need to sum are in one of two columns. Take this example: I have an ID field over which I will subtotal. Each entry has a v1 value and possibly a v2 value. I need to sum in a way that will take the v1 value, unless the v2 cell is not blank, in which case I would use the v2 value.
One way of doing this is by adding an extra column (I called it choose(v)) that does the conditional IF formula to pick the values to sum. Then, I can simply use this extra column as the sum_range in a SUMIF formula.
Assuming this data starts in cell A1, my formula for choose(v) would be
=IF(ISBLANK(C2),B2,C2)
and then my formula for subtotal would be
=SUMIF($A:$A,A2,$D:$D)
Is there a way to accomplish this subtotal without using this extra choose(v) column?
Perhaps the following:
=SUMIFS(B:B,A:A,A2,C:C,"")+SUMIFS(C:C,A:A,A2)
Quick and Dirty SUMPRODUCT:
=SUMPRODUCT(((($C$2:$C$7<>"")*$C$2:$C$7)+(($C$2:$C$7="")*$B$2:$B$7))*($A$2:$A$7=A2))
Or if one has the Dynamic Array formula FILTER:
=SUM(FILTER(CHOOSE(($C$2:$C$7="")+1,$C$2:$C$7,$B$2:$B$7),$A$2:$A$7=A2))

Count Blank Cells Until Value is Found

How can I find a count of blank cells until a value is found in a row?
I did some searching and found that I could use either
COUNTBLANK with INDIRECT or COUNTIF or MATCH with INDEX
But couldn't get it to work on any of them...
The formula should go into B5.
Example:
Thank you for the help.
Use MATCH() Function:
=MATCH(FALSE,ISBLANK(B1:F1),0)-1
That formula will give you the number of cells to the first non-blank cell, so if you substract one you’ll get the number of blank cells. As is an array formula confirm it with CRTL+SHIFT+ENTER instead of ENTER so you get the brackets {} in the formula:
{=MATCH(FALSE,ISBLANK(B1:F1),0)-1}
Please try this basic Lookup function. (This is normal function which means no need to confirm CTRL+Shift+Enter.)
This below function needs to be written on A1 then you can drag it down.
=LOOKUP(2,1/($A1:G1<>""),COLUMN($A1:G1))-2
You can use a combination of MATCH and MAX (or MIN) for this:
Formula in B5:
=MATCH(MAX(B1:G1),B1:G1,0)-1
Drag down

Excel array formula with wildcard

I have an array formula that refers to a drop down cell ($AG$7) to determine which cells to evaluate. This works well, however, I need to include an additional item in the drop down which is "All".
When this is selected, I want the array formula to use "*" to return all instances from the array, but i can't get it to work.
This is the formula I'm currently using;
={SUM(IF((tblSkillsMatrix[Role]=[#Role])*(INDIRECT("tblSkillsMatrix["&V$2&"]")=$AG$7),1,0))}
I've tried using
={SUM(IF((tblSkillsMatrix[Role]=[#Role])*(INDIRECT("tblSkillsMatrix["&V$2&"]")="*"&$AG$7),1,0))}
and
={SUM(IF((tblSkillsMatrix[Role]=[#Role])*(INDIRECT("tblSkillsMatrix["&V$2&"]")="*"&$AG$7&"*"),1,0))}
But these don't work.
Does anybody have any ideas?
Thanks
A explicit = comparison cannot use wildcards. COUTIFS and SUMIFS can. As far as I see, you want to count only (conditional sum 1 and 0).
Problem is, COUTIFS and SUMIFS will not deal with INDIRECT ranges. But INDIRECT can and should (because of its volatile bahavior) often replaced by INDEX- MATCH.
So:
=COUNTIFS(tblSkillsMatrix[role],[#role],INDEX(tblSkillsMatrix,,MATCH($V$2,tblSkillsMatrix[#Headers],0)),"*"&$AG$7)
If $AG$7 is empty then it counts independent of the column named in $V$2.
Btw.: Within a table (ListObject) this needs not be entered as a array formula.
This is not 100% replacement of your formula since it not works if $V$2 is empty and so no table column title is given. Your formula will then look at all columns but this is not possible using COUNTIFS where each additional range must have the same number of columns as the criteria_range1 argument. So if $V$2 shall also can be empty, then this will not work.
If so then you could use
{=SUM((tblSkillsMatrix[role]=[#role])*(LEFT(INDIRECT("tblSkillsMatrix["&$V$2&"]"),LEN($AG$7))=$AG$7))}
Advantage: both $V$2 and $AG$7can be empty.
Disadvantage: Volatile behavior of INDIRECT and this formula then must be a array formula even in a ListObject-table. It must be confirmed using Ctrl+Shift+Enter.

SUMIF with several OR criteria

The blue cell summates to 1, but that is not correct and it should summate to more because of the row text match with B47 row. Any ideas what's wrong?
SUMIF is not supposed to work with more than one criteria (you can't check multiple criteria within one SUMIF as you tried in your formula).
This formula will calculate the right result for you: =SUM(B3:BI3*(IFERROR(MATCH(B2:BI3,B47:AL47,0)>0,0))), this is an array formula, so you need to press CTRL+SHIFT+ENTER after it.
MATCH(...): look for all students whether they are in the list with requirments (this is the part which works only as array formula)
IFERROR(...): converts #N/A errors to 0
If I am not wrong, you are trying to calculate the number of students for a particular project with skill1 and skill2.
You may also try using COUNTIFS() function. This works for multiple criteria.

Multiple values for an AND/OR statement

Is it possible to combine AND (or OR) statement criteria to avoid repeating a cell name?
For example, I want to see if cell C2 contains the any of the numbers 2,3,5,7, or 10. I want to avoid writing
IF(AND(C2=2,C2=3... etc.
and simplify it to an array of the numbers like
IF(AND(C2=[2,3,5,7,10]...
Unfortunately, I have a lot more than just 5 numbers to add so it's getting be very laborious. Anyone have an easier way than repeating the cell name=__ over and over?
You can use an "array constant" like this
=IF(OR(C2={2,3,5,7,10}),"Yes","No")
.....or for a large set of numbers you could put all the numbers in a cell range, e.g. Z2:Z100 and do the same
=IF(OR(C2=$Z$2:$Z$100),"Yes","No")
although when you use a range rather than an array constant the formula becomes an "array formula" so needs to be confirmed with CTRL+SHIFT+ENTER
perhaps better to use COUNTIF and avoid "array entering"...
=IF(COUNTIF($Z$2:$Z$100,C2)>0,"Yes","No")
=IF(ISERROR(MATCH(C2,{2,3,5,7,11},0)),"no","yes")
No need to enter this as an array formula. How it works: MATCH returns a #N/A! error if it can't find the lookup value in the lookup array. ISERROR catches this.
But as barry houdini suggests, you may want to put your numbers in some range e.g. Z1:Z5 instead of hard-coding them into your formula. So you would have this formula instead:
=IF(ISERROR(MATCH(C2,Z1:Z5,0)),"no","yes")

Resources