EXCEL - SUM column if date matches TODAY() - excel

I've tried using SUMIF to obtain my results but it doesn't work properly.
I have a row of dates (XX/XX/XXXX format) and I would like to check this row for the current date.
If the row contains the current date, then I would like to sum the total of that column and row 5-20.
For example - today is 10/13/2016. I would like to search for TODAY() in a certain row (Row 1 for example), and if TODAY() is found, then total this column from row 1 down to row 3.
--A-- --B--
10/13/2016 10/14/16
1 50 10
2 10 4
3 5 6
The result should be 65 only IF the date matches TODAY().
I've also checked on giving the column letter based on the date but with no luck.
Any tips are appeciated! Thank you.

I think you can achieve this with a simple IF and a SUM
i.e. in your example above if you want the result to appear on the bottom row you can just use:
=if(B2=today(), sum(B3:B5), "")
This will display the sum at the bottom of the column for columns where the date = today and a blank in the other columns

You need to use the OFFSET function. You can find the documentation here: https://support.office.com/en-us/article/OFFSET-function-C8DE19AE-DD79-4B9B-A14E-B4D906D11B66
In your particular example the following formula will work:
=SUM(OFFSET(D2, 1, MATCH(B2, $D$2:$F$2, FALSE) - 1, 20))
You can see the formula working below. Assuming you know what the SUM formula is doing, I will explain what the OFFSET formula is doing:
First Parameter: Says start at cell D2
Second Parameter: This is how many row up/down do you want to do. In your case you need start at row below the date so '1' it is.
Third Parameter: This is how many columns to the right do you want to
go. Well the number of columns you want to go is based upon where
your date is. So this uses the match formula to figure out how far
to the right to go.
Fourth Parameter: This is how many row do you want to include. I just picked 20 to include the 20 rows below the selected cell.
You obviously need to modify the parameters a little bit to fit your exact data shape.

So I'll give it a shot:
{=SUM(HLOOKUP(TODAY(),Table_With_Dates_and_Three_Rows_Cell_Reference,{2,3,4}))}
NB: Don't type {} but put the formula inside it and then hit Ctrl+Shift+Enter to create what is called an array formula (it does array calculations element by element then submits the aggregating function value---in this case that is sum).

Related

To return the last value in a row for Date and Person to Action (VBA)

I wish to construct 2 current status columns so as find the last values in each row in Excel:
one for the last Date and the other for the last person who needs to act.
Please see the attached jpg To return the last values in a row for Date and Person to Act
I have tried to use the excel functions, namely, INDEX or LOOKUP but to no avail because of the 3 Remarks columns within the table.
I would appreciate it if you could advise me how to craft a VBA code to the above query.
From LC TAN 2020-02-13
You're on the right track.
you can use LOOKUP to return the last element in an array
BUT you have to ensure your array only has the elements that you want to consider
There is a variation of the INDEX function where you can enter an array for the column (or row) argument and return selected items. You enter the array, or arra constant, in a format like:
N(IF(1,*array or arrayConstant*))
So, a formula that would work for your requirements would be:
L6: =LOOKUP(2,1/LEN(INDEX($B6:$J6,N(IF(1,{2,5,8})))),INDEX($B6:$J6,N(IF(1,{2,5,8}))))
and fill down.
You can use MAX for the date to find the latest date in that row.
You can then use IFERROR and VLOOKUP to find the action with that date. i.e. lookup the date that MAX has returned in the first set of columns, and if that returns an error, look in the second. If the second returns an error, look in the third.
As per your sheet, the formula for L6 would be =MAX(B5:I5)
The formula for M6 would be =IFERROR(VLOOKUP(L5,B5:C5,2,FALSE),IFERROR(VLOOKUP(L5,E5:F5,2,FALSE),VLOOKUP(L5,H5:I5,2,FALSE)))
You can then drag the cells down to populate the date and action for every row. You could achieve the same with VBA if you wanted to, but I would have thought that this is the easiest way to get the the desired result.

How to use COUNTIF on date range - only counting duplicates once

Currently. I have it set up when someone enters information in column E (Action Taken) then the whole row will turn yellow so it is easily seen that that item is being dealt with.
Another conditional format that I have set up is that once 5 working days pass on the date entered into column F (Date Actioned) then the row will turn red alerting the user to chase up the issue again.
Every week the user will contact more suppliers on the list regarding the listed product, and fill in their action taken and date actioned.
What I am looking to do is to add up all the suppliers contacted in one week (i.e. week 1 , 05.02.18 to 09.02.18) Which I know can be done by using the formula;
=COUNTIFS(F4:F18,">=5/2/18",F4:F18,"<=9/2/2018")
HOWEVER I only want to count each company once! So even though between the date 05.02.18 to 09.02.18, 8 actions were carried out, they only contacted 4 suppliers.
Is this possible? (FYI the screenshots attached are just a quick mock-up of the real document which contains thousands of products and more in-depth information).
If you don't mind adding a couple of working columns, the following is a possible solution:
Step 1
Set up two cells to contain the min and max dates for your range that you used in your formula =COUNTIFS(F4:F18,">=5/2/18",F4:F18,"<=9/2/2018"). This will allow you to up date things without having to recopy the formula each time. I used cells E1 and G1 for min and max date respectively.
Step 2
In a new column generate a list of supplier IDs that match your criteria. I arbitrarily chose column H. I placed the following formula in H4 and copied down:
=IF(AND(F4>=$E$1,F4<=$G$1),A4,"")
Step 3
In a new column generate a list of the count of the first time a supplier ID occurs from column H and do not count blank spaces. I arbitrarily chose column I. I placed the following formula in I4 and copied down:
=--(AND(COUNTIF($H$4:H4,H4)=1,H4<>""))
Step 4
Take the sum of the results from step 3. I arbitrarily chose to place the following formula in I19:
=SUM(I4:I18)
The "cop out" route, if you were only doing the calculation for 1 week would be to have a Pivot Table, with the Company as the Rows and the Date as the Columns. Then filter your columns, and you get a row per Company that week.
The Full route means looking into Array Formulae - you type one of these like normal, but instead of pressing [Enter], you press [Ctrl]+[Shift]+[Enter], and the equation will show in curly braces. (This is why they are sometimes called "CSE Formula" for "Control, Shift, Enter")
~Warning - This is a long walk through how I calculated the final formula. Hopefully it will make sense though!~
An array formula lets you iterate through every row in a range, calculate them seperately, and then add them all together at the end. This gives us the outside term - everything goes inside a =SUM(..). Press [Ctrl]+[Shift]+[Enter], and this will display as {=SUM(..)}
Now, what calculation do we want to be doing per row? Well, for every row where column F is within date, you want 1 per company within date. Well, another was to say "per" is "divided by" (hence the "Percentage" symbol being "0 / 0" or "%", and the lesser knows "Permille" symbol being "0 / 00" or "‰")
For the sake of reproducibility, I am going to assume that your Count is being done in Cell J2, and you have the Start/End of week dates in Cells H2 and I2
The formula for Row 4 would start out as =IF(AND(F4>=$H2,F4<=$I2), 1/???, 0), where ??? is how many times the Company on row 4 appears. Unfortunately, the AND function does not work with Array Formula. Fortunately there is an easy workaround - since boolean True/False can be treated as binary 1/0, the AND operator is the same as multiplication. Converting from boolean to binary is fastest by double-negation, so AND(F4>=H2,F4<=I2) can be rewritten as --(F4>=H2)*--(F4<=I2), which will work fine with array formula, giving us =IF(--(F4>=H2)*--(F4<=I2), 1/???, 0)
Now, before we work out what ??? should be, I'm going to skip down to row 18. There is method to this madness, I promise! Following the rules laid out above, the formula for row 18 is =IF(--(F18>=H2)*--(F18<=I2), 1/???, 0) - fairly simple? Now, if we want to run this for all rows from 4 to 18, we just need to join the ranges. So, you would get =IF(--(F4:F18>=H2)*--(F4:F18<=I2), 1/???, 0) Turning this into an Array Formula would get you an array of "1/???"s and "0"s, so add it together with SUM to get a single 'flat' number: =SUM(IF(--(F4:F18>=H2)*--(F4:F18<=I2), 1/???, 0))
Remember that "method" I mentioned earlier? Well, if we were looking for a straight Count of actions taken, ignoring the Unique Companies constraint, we could make ??? = 1, to get =SUM(IF(--(F4:F18>=$H2)*--(F4:F18<=$I2), 1, 0)) and hit [Ctrl]+[Shift]+[Enter] - which would give the same result as =COUNTIF(F4:F18, ">="&H2, F4:F18, "<="&I2) - and changing the 1 to D4:D18 would be a SUMIF on Products. (Incidentally, you can remove the IF statement from the CountIf, since the Condition returns 1 or 0 already)
So, last step! What is ??? Well, it's a Count of rows where Date Actioned is within our date bounds, and Company is the same as the current row. So, for Row 4 you have COUNTIFS(B4:B18, B4, F4:F18, ">="&H2, F4:F18, "<="&I2), and for Row 18 you get COUNTIFS(B4:B18, B18, F4:F18, ">="&H2, F4:F18, "<="&I2), making the final ??? become COUNTIFS(B4:B18, B4:B18, F4:F18, ">="&H2, F4:F18, "<="&I2) (The trick here is that the Range arguments are treated as all the cells at once, but the Condition arguments are treated as an array of each cell one-at-a-time)
Now, some people might argue that you need to put your 1/COUNTIFS(B4:B18, B4:B18, F4:F18, ">="&H2, F4:F18, "<="&I2) inside an IFERROR to be safe - however, this is in the TRUE part of an IF statement referrring to the same row, so we know that if the COUNTIF is being evaluated then there will always be at least 1 row that matches.
So, if we stick it all together, and add a load of $ symbols to lock the rows/columns in place (so that you can drag down column J to calculate for different weeks/dates in columns H and I) you get the (slightly unwieldy) formula as follows:
=SUM(IF(--($F$4:$F$18>=$H2)*--($F$4:$F$18<=$I2), 1/COUNTIFS($B$4:$B$18, $B$4:$B$18, $F$4:$F$18, ">=" & $H2, $F$4:$F$18, "<=" & $I2), 0))
And, one last time - Don't forget to press [Ctrl]+[Shift]+[Enter]
(The 2 Date cells, $H2 and $I2 are the only terms I have left 'unlocked', and even then only on the Row)

Google Spreadsheet, SUM or MINUS of above cell in the column using ARRAYFORMULA in the first row

I'm learning to use array formulas and have been successful doing simple things like adding 2 columns together in a third column. For example, I can put =arrayformula(B:B+C:C) in D1 and it adds B and C for each row.
But now I have a situation where I want to subtract two numbers in the same column. I want to take the value of that column in the current row and subtract the previous row's value from it. Without array formulas this is simple: in O7 I put =N7-N6 and cop that down so O8 gets =N8-N7, etc. But that requires copying down every time - can I do the same thing with an array formula?
Basically, can I do something like =arrayformula(B:B+(B-1):(B-1)) ?
Context: column N is a monthly account balance. I would like to calculate how much that balanced changed each month. So for row 7, =N7-N6 gives me that difference. But I'm changing the entire spreadsheet to array formulas so I can stop pasting all of the formulas and I'm stuck on this one since it's comparing the same column.
I'm trying to get everything into Row 1 so my values and calculations can start in Row 2. For example, here's one of my formulas in Row 1:
arrayformula(if(row(A:A)=1,"Total gross income",if(LEN(B:B),B:B+C:C,"")))
Unfortunately, in Column O (the one I asked about originally) if I do this:
=arrayformula(if(row(A:A)=1,"Amount saved this month",if(row(A:A)>1,if(LEN(N:N),N2:N-N:N,""))))
Or this:
=arrayformula(if(row(A:A)=1,"Amount saved this month",if(row(A:A)>1,if(LEN(N:N),offset(N:N,1,0)-N:N,""))))
Every row is off by 1 - the result that should go in Row 3 goes in Row 2, etc. And if I do this:
=arrayformula(if(row(A:A)=1,"Amount saved this month",if(row(A:A)>1,if(LEN(N:N),N:N-offset(N:N,-1,0),""))))
Then it gives me an error because the offset function is trying to evaluate something out of range (possibly it starts with N1 and tries to grab a value 1 row above N1?)
Any advice on how to handle that out-of-range error?
I think the error is because of offset range N:N which starts from N1 and you are trying to shift it -1 or one cell up, which brings the formula out of sheet.
Try this formula instead:
=arrayformula(
{"Amount saved this month";
if(LEN(N2:N),N2:N-offset(N2:N,-1,0),"")})
It uses {} to make an array. See more info:
https://support.google.com/docs/answer/6208276?hl=en
Bonus. There is no reason to check row number now.

Excel (numbers) formula

this should be simple enough, but numbers (on OSX) keeps throwing an error about the ranges being different sizes.
I have a list of numbers, each with an associated date, and I want a sum of all numbers within a particular month (to give, on a separate sheet, a monthly total).
Here is what I've tried:
SUMIFS(
Sheet1::Table 1::D2:D84,
MONTH(Sheet1::Table 1::A2:A84), "=04",
YEAR(Sheet1::Table 1::A2:A84), "=2014"
)
Sorry if this is a stupid question, but I've tried fiddling with it and it just won't accept it.
Thanks in advance.
You cannot put a function inside the range:
=SUMIFS(C1:C25;Month(A1:A25);"=3")
than you need to add two (hidden?) columns with Month & year function.
After you build SUMIFS based on the new columns
=SUMIFS(C1:C25;D1:D25;"=4";E1:E25;"=2014")
sum all value from C1 to C25 if column of month (D) is equal to 4 and column of year (E) is equal to 2014.
I would suggest considering using a SUMIFS function with an upper\lower limit, and then either referencing a cell with the dates, or using their numerical value in the formula (the former is my preference, to reduce hard coded values = easily updated\reused). So something like:
=SUMIFS(D2:D84, A2:A84, ">="&E1, A2:A84, "<="&E2)
In this example:
column 'D' has the values you want to sum
column 'A' has the date values
columns 'B' and 'C' are treated as irrelevant (for the sake of this formula)
column 'E' has 2 values, in row 1, the lower limit (for this specific question, the first of April) and in row 2 the upper limit (for this specific question, the final day of April)
Then have your lower limit for dates (the first day from when you would like column 'D' to be counted) in cell E1, and your date upper limit in E2.
Easily updated for future months, so might save you some work down the line.
The next easier option would be to update it to be formatted as a table, because your formula would be slightly more legible, add in some named ranges (in this case, E1 = 'lowerlimit' and E2 = 'upperlimit) to once again make it easier to read the formula, in which case you'd end up with something like:
=SUMIFS(table[FigureToBeAccrued], table[dates], ">="&lowerLimit, table[dates], "<="&upperlimit)
Might've overcooked this answer, it's my first, so wanted to make sure I didn't skimp. Let me know if you've got any follow up questions.

Looking for formula to extract specific values from a row containing numbers and blanks

I have a sheet with rows of data, with many columns. I am looking for help on a formula that will extract the sum of the smallest 3 numbers in a row based on the last 5 values entered. Note that not all the rows will have values for each column, so the first value found on each row will may be found in a different column.
To determine the sum of the smallest 3 I am using the formula =SUM(SMALL(B3:R3,{1,2,3})), Unfortunately, that formula is looking at the entire range. Again, I am looking for help that with a formula that will select only the last 5 values posted.
Here is simple example. The results for each line show the totals that should be determined. Again, it needs to look for the sum of the smallest 3 based on the last 5 posted (in the example below the range would be col. 1 thru 10, with col 10 having the latest postings).
Ex.
1.....2.....3......4......5.....6.....7.....8......9.....10...... Result
31.........44....51....36..........44...34....36....38.......106 (34+36+34)
35..31...44...40.....38...52..........42....37...............115 (37+38+40)
Hope this is understandable. I am looking for a formula solution vs a VBA macro solution because of my users. Thanks for any help!!
Now that you clarified the question, I have an answer for you. This is fairly ugly but it gets the job done. You might want to hide the columns with the intermediate results - or you could get adventurous and "nest" the expressions. This makes it really hard to understand / debug though. If there's a smarter way to do this I am always open to learning.
Assuming you have the data in columns A through J, starting in row 2, put the following in cell L2:P2:
=MATCH(9999, A2:J2,1)
=MATCH(9999,OFFSET($A2,0,0, 1, L2-1)) ... copy this by dragging right to the next 2 columns
=MATCH(9999,OFFSET($A2,0,0, 1, M2-1))
=MATCH(9999,OFFSET($A2,0,0, 1, N2-1))
=MATCH(9999,OFFSET($A2,0,0, 1, O2-1))
The first line finds the last cell with data in it; the next ones find the last cell "not including the last cell", and so they work backwards. The result is a number corresponding to the columns with data. For your example, this gives
10 9 8 7 5
9 8 6 5 4
Now we want to find the sum of the smallest 3 of these: put the following equation in cell Q2:
=SUM(SMALL(INDIRECT("RC["&P2-17&"]:RC["&L2-17&"]",FALSE),{1,2,3}))
Working from the inside out:
RC["&P2-17"] results in RC[-12], which is "the cell 12 to the left of this one".
That is the first of the "last five cells with data", cell E2
RC["&L2-17"] results in RC[-7], the last cell with data in this row
FALSE use "RC" rather than "A1" indexing
INDIRECT turn string into an address (in this case a range)
SMALL find the 3 smallest values in this range
SUM and add them together.
This formula did indeed give me 106, 115 for the example you provided.
I would hide columns L through P so you only see the result (and not the intermediate stuff).

Resources