How to use SUMIF formula over jagged sum range - excel-formula

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))

Related

Excel Sumif with number

=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))

EXCEL: When dragging cells to the right I need to use information stored in columns not rows (Not sure how to ask this properly)

It's probably a simple problem, but I did not even know the keywords to google it ;/. Let's say I have this data :
Now I also have this litle formula:
If I know drag the C cell to the right, Excel will attempt the following caluclation:
=2+B1
What I want him to do is to attempt this calculation
=2+A2
Of course the easiest solution would be to store my initial data in one row instead of 1 column, but it is really inconvenient for me. Thanks for any help
You can use the indirect() method to reference a cell by it's "String identifier", i.e. "A3". When filling out to the right, use CONCATENATE() and COLUMN() to create your String identifiers {A1,A2,A3,A4,A5...} as required:
=2+INDIRECT(CONCATENATE("A";COLUMN()-2))
This will result in the following:
Side-Node: If you want this for some x/y-Grid-Generation, you can also be lazy,
and just insert =COLUMN() for every cell from "A1 - Z1" and ROW() for every cell from "A2 - A24".
(Or even avoid these at all and directly perform your actual calculation by using column() and row() as replacement for your x/y.
You may try using a combination of the INDIRECT and COLUMN functions:
=2+INDIRECT("A"&(COLUMN()-2))
You would paste the above formula into cell C1, and then drag across to the right however many columns/rows you wanted to cover.
This would result in the following:
This works because COLUMN()-2 returns 1 for the C column, 2 for the D column, and so on. Therefore, the formula will be calling INDIRECT on A1, A2, etc. for column C, D, and so on.
In general, if you want relative references to move down as cells are dragged to the right, you can use this:
Instead of:
= 2+A1
Do:
= 2+INDEX($A:$A,COLUMN()+<offset>)
Where <offset> is whatever offset you need. The offset will change depending on which column the starting formula is located in.
INDEX should be preferred over INDIRECT because INDIRECT is volatile (must recalculate after any change to the workbook) but INDEX is not (only recalculated when one of the inputs the formula, in this case $A:$A, changes).

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.

CountIf cell value meets a condition

Hi I have a row of calculated values that I need to count based on a condition.
I have the conditions working in conditional formatting so that is the condition is met the cell changes color, however I need to find the totals of each color.
=AND($V1/$Z1>0.5, $V1/$Z1<=0.79)
so for this I want to only count values if this statement is true
=COUNTIF(Z:Z, (AND($V1/$Z1>0.5, $V1/$Z1<=0.79)))
currently this returns 0 when there is 10 values that meet this criteria
does anyone know if countif can be used like this?
I can see your issue, I've had a play around and am unable to crack it, if you wish to keep it in a singular cell you'll probably need to go down the route of an array formula. Its probably complicating it too much and you should look to have a helper column,
in Column AA, have the formula =$v1/$z1, then for your count write:
=countifs(AA:AA,">0.5",AA:AA,"<=0.79")
This can be done without a helper column using the Sumproduct() function.
=SUMPRODUCT(--($V$1:$V$100/$Z$1:$Z$100>0.5),--($V$1:$V$100/$Z$1:$Z$100<=0.79))
or
=SUMPRODUCT(($V$1:$V$100/$Z$1:$Z$100>0.5)*($V$1:$V$100/$Z$1:$Z$100<=0.79))
This will count all instances where the values in V1 to V100 divided by the values in Z1 to Z100 are between 0.5 and 0.79
Note that SumProduct is essentially an array formula (even though it does not require confirmation with Ctrl-Shift-Enter, but it evaluates each range as an array), so you don't want to use it with whole column references. If you want to retain calculation speed, make sure to refer to used rows only, not gazillions of empty cells.

Dynamical SUMIF command

If it is possible, I'd like to create a formula that will allow me the following:
Formula must be in the entire column or in this example, in the range B1:B5. The formula is based on a condition, that when the total sum of cells from column A is lower D1, than it gives "X". If the total sum is over D1, then it gives an empty field - "".
In this example the total sum of the cells, that are over D1 value is in the first 3 rows, hence the three X-es, and then it stops.
(source: shrani.si)
.
I presume it would be possible to do this with multiple SUMIF commands, but does anyone know a smoother solution for this?
Thanks!
You can do this easily by using an absolute reference for the starting point of a SUM and using a relative reference for the end point. When copied down, this formulas works fine.
=IF(SUM($A$1:A1)<$D$1,"x","")
Results
Try this
=IF(SUM(OFFSET(A1,0,0,$A$1:A1,1))>$D$1,"X","")
This formula should start at B1 and then you use auto-increment to populate other cells

Resources