SUMIF date in column B is less than date in column C - excel

I have a list of values in Column A and want to sum these values where the date in Column B is less than Column C.
Example
In this example the correct value would be 2100.
I have previously had to complete this task with reference to a single date (e.g. the date contained in C3) and used the formula:
=SUMIF(B2:B11,"<="&C3,A2:A11)
However in this instance I need each date in B to be less than or equal to the date in C. I have tried:
=SUMIF(B2:B11,"<="&C2:C11,A2:A11)
But I get a value of 0. Any ideas?

Option A - Helper column
The simplest approach for any scenario requiring working out on a row by row basis whether to do something or other - be it a sum, Lookup, etc - , is to use a 'helper' column alongside your data that uses a formula to work out whether it should or should not be included, typically returning 'True' if to be included.
With your data layout, in column D add a calculation that works out the difference and therefore whether the row should be included, such as:
=C2-B2 or =C2>B2 dragged down
The SUMIFS calc then becomes =SUMIFS(A2:A11,D2:D11,">0") or, for the general case with more complex criteria, =SUMIFS(A2:A11,D2:D11,TRUE)
This approach is excellent if you have a large number of complex criteria, perhaps varying by rows or perhaps requiring multiple AND() OR() and other logical evaluations (is a product ID x and is a customer ID y and is the value > z and is the days between purchase order being submitted and goods received more than 30 days) etc, to determine whether a row should be included in some further function.
Option B - Array formula
Alternatively, you can avoid the need for a working column by using an array formula that performs the comparisons in the formula. Under the data above this would be like:
=SUM(IF(B2:B11<C2:C11,A2:A11,0)) entered with Ctrl + Shift + Enter

Related

VLOOKUP formula... is this the right formula for what I am trying to accomplish?

I want to lookup a specific date from cell E2 within a list of dates (column A) and return the corresponding value in column B from the matching date values IF column D does not equal "NA". I want the column of revised dates (RevDate column) to coincide with the specific Q measurement when the tss data was <> "NA". This will give me the specific Q value when tss was measured on a specific date.
Formulas I have tried in Excel:
=IF(D2<>"NA",VLOOKUP(E2,$A$2:$D$445196,4,FALSE),0)
=IF(VLOOKUP(E2,A$2:D$445196,2,FALSE)="NA","",)
I feel I am close.... maybe????
If you are going to have per date in A column just a single value in column D that is not NA(as per your sample), then you can use FILTER. VLOKUP will return the first match, and this is not what you want.
=FILTER($B$2:$B$445196, ($D$2:$D$445196<>"NA") * ($A$2:$A$445196=E2))
In case FILTER returns multiple rows, you would need to concatenate the result as follow:
=TEXTJOIN(",",,FILTER($B$2:$B$445196, ($D$2:$D$445196<>"NA")
* ($A$2:$A$445196=E2), "Not Found"))
Added also not found condition (if not it returns #N/A), that covers the case of 10/3/2010 for example. You can replace with an empty string as per in your second formula.

Return value in a specific column based on array formula result

I am using an array formula to find the largest value within a given month. Photo below ('Range of values') shows the values for each month, and I am selecting September as the criteria ("K5" in the formula below). Cell K5 will change based on the specific month I am looking for:
Formula:
{=MAX(IF(E8:P8=K5,E12:P21,""))}
Result:
63,490
Requirement:
I need to have a cell with the result, and a cell next to it with the corresponding 'Location', which in this case would be 6.
What would be the best formula to use in the case where you are not confined to a single column for the value lookup?
Typical Vlookup and Index/Match as I understand are limited as they require a single column to look up a value. The array is outside of that scope, but I feel I may be overthinking it, but I don't know.
if you have Excel 365 current channel you can use this formula to return both values:
=LET(data,A1:D5,
selectMonth,B7,
dataMonth,CHOOSECOLS(data,1,MATCH(selectMonth,CHOOSEROWS(data,1),0)),
TAKE(SORT(dataMonth,2,-1),2))
The basic idea is to first reduce the data range to the first column and the month that should be evaluated.
Then sort that "range" descending by the months values (= column 2 of new range) and take the first 2 rows (including header) - as this is the max value.

Sum column based on conditions for subsums

So I have a table which basically looks as follows:
Criterion Value
1 -5
1 1
2 5
2 5
3 2
3 -1
I want to sum the values in column B based on the criteria in column A, but only if the sum for an individual criterion is not negative. So for example if I ask for the sum of all values where criterion is between 1 and 3, the result should be 11 (the values for criterion 1 not being included in the sum because they add up to a negative number.
My first idea was to add a third column with a sumif([criterion];[#criterion];[value]) and then use a sumifs function which checks whether that that third column is negative. However, my table has +100k lines and with that many sumif functions it becomes intolerably slow.
I know I could create a pivot table to the same effect, but that has two drawbacks: I would have to create a separate sheet, which would add complexity, and my table is frequently updated which means I would have to manually update that pivot table every time to allow for downstream calculations. NBD and I could do that as a last resort, but I wonder whether there isn't a more elegant way to solve this problem.
I would want to avoid VBA to avoid complexity (the sheet will be used by other persons).
Thank you
This can be easily done using UNIQUE() and the two versions of SUMIF() in this way:
First collect all the criteria with =UNIQUE(A2:A7) -- Assuming your data are in columns A and B starting from row 2, this goes in cell C2, with "Criteria" in C1
Compute the subtotals for all criteria using =SUMIF($A$2:$A$7, C2, $B$2:$B$7) -- This goes in cell D2 and extends as the criteria do, "Partials" in cell D1
sum all the data in step 2 yielding a positive sum with =SUMIF(D2:D7, ">0") in cell E2
If you have a lot of data I suggest to use the column references to avoid absolute references and the need to adjust the formulas as data change (in number):
The first formula becomes =UNIQUE(A:A) -- Don't care about the heading being taken (strings and empty cells are not summed)
For the second formula use =SUMIF(A:A, C2, B:B)
Use =SUMIF(D:D, ">0") for the last step
This should be reasonably fast, using just as many extra cells as the number of distinct criteria (multiplied by 2).

Sum column of values where separate column contains duplicate

I need to sum all values in Column A where Column B is a duplicate.
Above is a sample of the data. Column B has urls and Column A has counts for the urls. What I want is to sum the values in Column A for duplicate values in Column B.
Example:
The output for _.apelabs.net should be 6.
How can I achieve this?
I think you are looking for the function =COUNTIF(Range,Criteria)
Here is a link that shows a usage example.
As #Andresson stated, if you're trying to count the number of times a specific url appears, you might want to use the COUNTIF function: =COUNTIF(range, criteria).
COUNTIF Example:
Using =COUNTIF(B:B, "_.apelabs.net")
would return 3 in your sample data (assuming your image includes the only instances of "_.apelabs.net").
This example of the COUNTIF function is the same as saying, "count the total number of times a cell in Column B (i.e. B:B) equals "_.apelabs.net"."
However, if you're wanting to sum together all the values in Column A where the corresponding url in Column B matches the given criteria, you'll want the SUMIF function: =SUMIF(range, criteria, [sum_range]).
SUMIF Example:
Using =SUMIF(B:B, "_.apelabs.net", A:A)
would return 5 in your sample data (again assuming your image includes the only instances of "_.apelabs.net").
This example of the SUMIF function is the same as saying, "each time a cell in Column B (i.e. B:B) equals "_.apelabs.net", sum together the values in Column A (i.e. A:A) that are located in the same row as each "_.apelabs.net" found in Column B."
Additionally, you can also use a pivot table, as #ScottCraner suggested. It's all a matter in how you want to present your findings.

Count values in column E if the date in column F is greater than today

How do you count values in column E if the date in column F is greater than today.
This is what i have so far - but it returns 0.
=COUNTIF(E:E,F:F>=TODAY())
Please try:
=COUNTIFS(E:E,"<>",F:F,">="&TODAY())
Not sure why you are trying to use column E at all. The number of corresponding cells in E is the same as the number of column F cells matching criteria. It is irrelevant to finding the number of values in column F greater than today. First parameter is the range you want to count values in and the second is just the criteria. Try this:
=COUNTIF(F:F,">="&TODAY())
I prefer using sumproduct. THis can be used to count and find a weighted average. For counting, you wrap the range in --() and anything within that row is counted as 1. If you include a conditional statement, the row is only counted if the condition is true. You can add several conditions to filter out more data as needed. In the field below, I have the current date set to F12 or you can use the current date.
=SUMPRODUCT(--(E2:E10),--(F2:F10>F12))
There seems to be a bit of confusion about wether you want to count or sum the values in column E if the date is equal to or greater than todays.
Here's the sum formula
=SUM(IF(F2:F5>=TODAY(),E2:E5,0))
Hit ctrl+alt+delete so you get the curly brackets.
It should look like {=SUM(IF(F2:F5>=TODAY(),E2:E5,0))}
Use the same formula but with count if you want it to count.
=count(IF(F2:F5>=TODAY(),E2:E5,0))
Again, use ctrl+alt+delete

Resources