excel count/sum stop count/sum match? - excel

I have tried to see if this question has been asked before, but I can't seem to find an answer.
I have a column of cells (>3000 rows), with either a value of 1 or 0 (call this column A). The value will depend on the value in column B (which will contain either a value or nothing). The values in column B are a SUMIFS function based, summing from column C, and based on months in column D.
The values in B are paid out on the first business day of the next month. So, the SUMIFS function will calculate the dates that match the last month. This works well in theory, however, not every first business day is the first day of the month. This leads the SUMIFS function to not include everything in the correct month, and allows for some discrepancy, which, when you are dealing with people's money is not great. Further, this discrepancy is compounded across multiple periods (in some cases, there are over 100 periods, and a discrepancy of $1 in period 1 amounts to nearly $1000 in period 100)
What I am wondering is:
Is there any way that I can tell the SUMIFS function (column B) to stop when the value in column A is 0? This would tell the SUM function start the summing from the current value in column B and continue the function to the cell below the preceding value in column B.
I've seen suggestions that the MATCH function may work, but I can't see how to do this with either COUNT or SUM.
For security reasons, this solution needs to be entered into the cell, and can't be VBA. Also, it can't be too large, as it will need to be replicated across 200 worksheets in the workbook (not my file originally, and I would have done it differently, but that is another story). There is no problem entering another column or two if that is required.
Any help is gratefully appreciated.
EDIT:
Unfortunately, I can't post an image of the screenshot. I've included a similar screenshot (columns are not the same layout, but hopefully it gives the idea) here:
Rates calculations
The SUMIF formula is (for B2)
=SUMIFS(C2:C35,D2:D35,D2-1,A2:A35,1)
This works fine if I want all the values in the month, irrelevant of when the payment was made.
However, what I need the formula to do is:
SUM (C2:C35,D2:D35,D2-1, but stop when the first 0 is encountered in A2:A35)
Thanks

The INDEX function can provide a valid cell reference to stop using a MATCH function to find an exact match on 0.
This formula is a bit of a guess as there was no sample data to reference but I believe I have understood your parameters.
=SUMIFS(C2:index(C2:C35, match(0, A2:A35, 0)), D2:index(D2:D35, match(0, A2:A35, 0)), D2-1)
This seems to be something that will stand-alone and not be filled down so I have left the cell addresses relative as per your sample(s).

Related

Give Sum for matching Column and Row values - repeating variables

The first table below shows how much each person owes and who pays it (it's part of a larger model so I simplified it for our purposes here).
Our goal in the second table below is to give a sum when both the column and row value match.
For example: A (column C) paid $244.17 (D36:H48) in expenses for B (row 35).
Where am I wrong here? I have tried different methods suggested here.
This is another alternative, that only requires to extend the formula down, but not to the left, because on each row it returns an array with all column values. In cell I3 enter the following formula:
=MMULT(N(TRANSPOSE($A$3:$A$15=H3)),IF($B$3:$F$15="", 0, $B$3:$F$15))
or using LET to avoid repetition of the same range:
=LET(set, $B$3:$F$15, MMULT(N(TRANSPOSE($A$3:$A$15=H3)),IF(set="", 0, set))
Notes:
MMULT only works with numeric values, so empty cells need to be converted.
You can replace TRANSPOSE with TOROW if you want.
$-notation is not required in H3, because we extend the formula only down
Here is the output:
Note: This solution assumes header values to compare are the same, i.e. same values for Paid For (I2:M2) and Paid By (H3:H7). Which is the most common situation. That is why in the formula only Paid By column is used. If that is not the case, then the solution provided by #JB-007 is more flexible, because the values can be different, but then you need to extend the formula in both directions.
screenshot/s here refer:
=SUM($C$4:$E$6*($C$3:$E$3=C$8)*($B$4:$B$6=$B9))
(sumifs will really struglly to work across different dimensions)
PS - as you'll see most will advise sumproduct - I think it's overdue deprecation because there's very little (if anything) you can do with sumproduct that you cannot with sum. You can even do counts with sum SUM(1*($C$3:$E$3=C$8)*($B$4:$B$6=$B9))) returns the count of where these values are equivalent...
Save yourself the extra seven letters over and over! ☺

Invoice total in row n, payment in row n+k, using dates

I have a table of payments to calculate interest. The column where the payment is applied takes its values from the column where the invoice totals are listed, however, the payment is applied k days after the period ends.
I had partial success doing it using this formula:
IFERROR(INDEX($F$12:$F$25,MATCH(D12,$G$12:$G$25,1)),0)
Where column G is a helper column with the dates of payment, basically period end + k, but since it only accounts for the period end, in monthly and semimonthly periods, sometimes the nearest lower date of payment was on the same period, so I MUST also account for the period start for this to not happen. I've been helped using an array formula like this:
=IFERROR(INDEX(F:F,SMALL(IF(F$12:F12>0,ROW(F$12:F12)),COUNT(1/((C$12:C12-C$12>C$7)+(D$12:D12-C$12>C$7))))),0)
And it works well and it does not require a helper column. But since it's an array formula, and this table is not for my usage, that's not suitable.
I would like to know if I can do this without an array formula and built-in excel 2013 functions.
Edit:
This formula does it:
=SUMPRODUCT(($D$12:$D$25+$C$7>=C12)*($D$12:$D$25+$C$7<=D12)*($F$12:$F$25))
But if there are blanks in column D that result from a formula, it returns an error. So the following formula is more stable:
=SUMIFS($F$12:$F$25,$D$12:$D$25,">="&C12-$C$7,$D$12:$D$25,"<="&D12-$C$7)
This one effectively places the payment rows within the range of dates it belongs to.
At least you can replace SMALL with AGGREGATE like this:
=IFERROR(INDEX(F:F;AGGREGATE(15;6;(ROW(F$12:F12)/(F$12:F12>0));COUNT(1/((C$12:C12-C$12>C$7)+(D$12:D12-C$12>C$7)))));0)
AGGREGATE(15;6;;) is the same as SMALL, but it ignores errors. This lets you switch out the IF(F$12:F12>0,ROW(F$12:F12)) for the quotient (ROW(F$12:F12)/(F$12:F12>0)). Every row-number divided by a FALSE produces an error which gets ignored by AGGREGATE.
For the COUNT-part I cannot say, what it is doing, as my results don't look like yours (i copied your formula).
I guess it works as an offset.
Can you test my formula and tell me if it is working without cse? Else we need to find a replacement for the COUNT-part. I currently cant test it as I am on Office 365 and don't know if i can activate the old CSE-functionality.

If function with formula to calculate difference between dates

I am trying to find a difference between 2 dates using networkdays and additionally if both dates are equal, have to make the value as 0. But unable to get the result.
You can try
if(DATEVALUE(A1)=DATEVALUE(A2),0,NETWORKDAYS(A1+1,B1)
#Ron Rosenfeld has pointed out that my testing led to wrong conclusions. Therefore I increased the volume of my tests. They continue to show that ...
Comparing the two dates and adding a day gives erratic results, and that
The naked NETWORKDAYS function as designed by Microsoft gives the most useful result.
In the table below the original function is in column C, your function (modified to work by #Ron Rosenfeld) in column D and two variations thereof in columns E and F. The lower part of the table shows results where both days are the same while the dates are 2 days apart in the upper part.
The tables show that the original formula counts both the start and the end days as well as all days between them, subtracting weekend days, except when start and end days are the same. In other words, the original function already treats the case of A1=B1 differently.
However, if an adjustment is to be made it should preferably be made to the result of the formula, not be modifying the date before they are processed. This is demonstrated in column F.
The formula in column E takes up your attempt to modify one of the dates (the end date could be modified too) and makes this conditional. The difference as compared to your formula is that you apply in fact two separate calculations, one where the result is always 0 (when dates are equal) and the other where the start date is advanced by one day unconditionally. If it suits your purposes that method can still be applied but the formula in column E shows how the date modification can be made conditional.
The need to apply conditions arises from the essential shortcoming of your formula in that it applies the wrong condition. Different treatment for when dates are equal is already incorporated in the basic function. Any further modification must take the involved weekdays into account, not (necessarily) only the interval between the dates.
Why do you put your formula arguments in quotes? That just changes them into strings, which is why your formula doesn't work.
I assume from your formula that you just don't want to count the first day. In which case it will work as you have it, if you merely remove the double quote marks.

how to group same values into Excel array

I have a duplicate value in column A with different value in column B and column C.
For example:
There are 3 column which is A, B and C.
- A has duplicate value which is serial number
- B is whether it fail the test or not
- C is the time for testing.
Is it possible with Excel to find time difference between time for first fail and pass?
I want to delete the data that have less than 12 hour so that I know the things don't need rework, just retest. I want to know the exact number of modules that need rework.
=IF(AND(B7 = "pass",B6 = "fail", A7 = A6),TEXT(C7-C6, "h:mm"), "")
To get the difference between last fail and pass use this formula in cell D7. If the cell in column B is pass and previous cell was a fail, it will work out the time difference between the previous cell that was a fail. It will also check that the cell in column A matches previous cell in column A. Can also try using Index / Match or Vlookup to get the first fail by formula. As Tim Williams said a pivot table will also help. I don't use them much, so I'm not sure how to get the time difference with a pivot table, but it'll make viewing the data easier.
You could also try adapting this formula, by nesting conditions to get the previous cell that is the first fail. Work out the maximum number of cells between a pass and a first fail, and nest it that many times. If there are cases where the fail time is later than the pass it will throw an error. If you have multiple consecutive pass cells, for the same element you'd need to add more conditions to account for that, but if there's only 1 pass per element this should work.
=IF(AND(B7="pass",B5="fail",A7=A5),TEXT(C7-C5,"h:mm"),IF(AND(B7="pass",B6="fail",A7=A6),TEXT(C7-C6,"h:mm"),""))

Excel SUMIF add Multiple Criteria

I am using this formula for SUMIF which is working fine, but I need to add another criteria which is the DATE. I only want the jobs to sum total if the date is the same in column A. How do I accomplish this? When I use SUMIFS I get an error "too few arguments".
=SUMIF($B$2:$B$786,I2,$F$2:$F$786)
Setting the Stage
When making my initial response, I didn't notice that the OP's sample data included two separate data ranges. There is the main "table" with columns including DATETIME, PRODUCT and AVG CYCLE MINUTES. These are the data to be summed across. However, the sums are not to appear against these rows, but against the rows in the second "table" which has the column REFERENCE LIST. REFERENCE LIST matches with the PRODUCT column in the first table and so provides one of the criteria for the SUMIF(S). The second criteria was to be DATE. However, since the second table doesn't include a date column it isn't obvious where this should come from.
In discussion with the OP, we realised that we wanted a the total (or, as it turned out, average) of "AVG CYCLE MINUTES" for each combination of DATETIME and PRODUCT. I walked the OP through the process of creating a PivotTable to do this.
Options
If we want to achieve the same or similar by means of SUMIF or SUMIFS, we need to make a decision about the DATE criteria. Either (a) the second table needs to include dates as well as PRODUCTs, or (b) we need to find a way to pick the date we're interested in.
Sum for Every Combination of DATE and PRODUCT
For option (a), an answer similar to my original one would work:
=SUMIFS(F:F,B:B,I2,A:A,J2)
where column J is the new column of dates. The full list of date/product combinations could have been swiftly produced by copying the relevant columns of the main data to elsewhere and using Excel's "remove duplicates" functionality.
Sum for single DATE per PRODUCT
For option (b), if you wanted to sum up all the data relating to "today", that could be done using:
=SUMIFS(F:F, B:B, I2, A:A, today())
(with credit to #JNevill).
What else might we want? Perhaps the most recent date the PRODUCT appears against? Or the earliest? If you have EXCEL 2016 (or better) ...
=SUMIFS(F:F, B:B, I2, A:A, MAXIFS(A:A,B:B,I2))
This would give the total minutes for the relevant PRODUCT on the latest date recorded for that PRODUCT. For the earliest date replace MAXIFS with MINIFS.
Alternatively, if the data is sorted so that the date you want will be the first to appear against any given PRODUCT you can use:
=SUMIFS(F:F, B:B, I2, A:A, INDEX(A:A,MATCH(I2,I:I,0)))
Miscellanea
I'd normally use VLOOKUP rather than INDEX/MATCH (a habit I've yet to acquire), but in the current data structure the columns are in the wrong order for that.
Since further discussion revealed that the OP actually wanted averages not totals, it's worth noting the existence of AVERAGEIFS.
NOTE: in my original answer (below), I reference the exact ranges rather than entire columns. There may be some marginal performance loss doing things as above, but I've never noticed. Though you need to be sure there are no extra data beneath the stuff you're interested in. On the other hand, there are definite benefits, it's easier to enter the formula and it will not need amending for larger (or smaller) data sets. (Thanks for reminding me of this #Jeeped)
NOTE 2: Since there is there is nothing you can do with SUMIF that can't also be done with SUMIFS, there is no harm in using the latter even when the former would suffice. That way you only have one function to remember and it's the most useful one. (Another good idea from #Jeeped)
Original Answer
As others have said, I think you want SUMIFS. Here the sum_range comes to the front, and you follow that with pairs of "criteria range"s and "criteria" like this:
=SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)
In your case, I think that means you want:
=SUMIFS($F$2:$F$786,$B$2:$B$786,I2,$A$2:$A$786,A2)
When I wrote this, the relevant Microsoft Support page was here

Resources