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.
Related
I want the code value in column B if the handset matches and the date is between the date from and the date to.
How the results should look:
Since you problem involve Date Range, therefore Vlookup & Index match is not possible to solve, I will use If + AND formula to solve your problem:
=IF(AND(E9>$G$3,E9<$H$3,F9=$E$3),$F$3,
IF(AND(E9>$G$4,E9<$H$4,F9=$E$4),$F$4,
IF(AND(E9>$G$5,E9<$H$5,F9=$E$5),$F$5,
IF(AND(E9>$G$6,E9<$H$6,F9=$E$6),$F$6,""))))
If you are able to add a column, one possible solution without using VBA would be to use a combination of SUMIFS and XLOOKUP formulas.
In column E, add a unique identification number (e.g., 1, 2, 3, 4, 5, etc.). You could reference the row number or manually fill down the numbers or whatever. It wouldn't matter as long as the values are unique and all numbers (no text).
Then, use a SUMIFS formula to sum Column E if (1) the handset number matches, (2) the date is greater than or equal to the start date, and (3) the date is less than or equal to the finish date. As long as there are no overlaps in the date ranges for each handset, this will return the unique ID number. Depending on the dataset, you might have to play with the less/greater than or equal to vs just less/greater than.
=SUMIFS(E:E,A:A,I2,C:C,"<="&H2,D:D,">="&H2)
Then, use the XLOOKUP to return the code based on the unique ID. In this example, I combined the SUMIFS and XLOOKUP in one formula, but you could also do it in two columns to provide better visibility.
=XLOOKUP(SUMIFS(E:E,A:A,I2,C:C,"<="&H2,D:D,">="&H2),E:E,B:B,"NOT FOUND",0,1)
Here's an example.
screenshot
I am trying to lookup a part number in a separate table array, the same value could be in multiple rows. The formula should find each instance of the value in the other table, move to a date column and determine which months the value exists in and which row it belongs to. The entire table B3:F15 should be automated. I have attached an image with proper explanation of what I am trying to accomplish if at all possible.
The formulas would be entered into B3:F15. These are the cells where the data will get pulled into. Each row will search for its corresponding Part Number in column A. I.e, B3 to F3 is only looking for A3 data. The rows are used to determine if a Part number in L2:P4 matches their row value in Column A and if was used in that month belonging to months B2:F2. If the Part number was used in the corresponding month then it will output the Plant # from Column I. In some cases the Part numbers in L2:P4 can exist in multiple rows, but they are unique to each column.
As an example I have manually filled in data for PN1001 and PN1021. For PN1001, this belongs to B3:F3. Each cell in B3:F3 will search the array L2:P4 and realize it is found only once and in M4, so it will look at the dates from its row, J4 and K4, and determine which months it was used in. Since it was used in Jan, Feb, and Mar, it will output the Plant # into D3, E3, F3. In the example of PN1021 it is the same but in this case PN1021 exists in L2 and L4, so it will take the date of J2,K2, and J4,K4.
Some Part numbers can be a combination of letters and numbers, some may just be numbers.
In terms of how to build the formula I am not sure what combination of Index/Match/Lookup I should be using. My theory is that each cell in B3:F15 would include a formula that be =MATCH(Lookup(columnA with L3:P4)) (but how do you get it to lookup multiple instances??) Some research lead me to use this concept to find multiple instances and point to the row #.
SMALL(IF(Lookup Range = Lookup Value, Row(Lookup Range),Row ()-# of rows below start row of Lookup Range)
Once I can find each instance, then Index the row and compare if the cell in B3 is greater than J3 and less than K3 to determine the months which should have a value entered. IFYES, then output column I from the row number.
If you have any better solutions or ideas to perform this action then please provide feedback. Thanks in advance for the support.
I think the formula below will do what you want. I created a table out of your I1:P4 data, and used structured references, as I find it easier to follow.
B3: =IFERROR(
INDEX(partsTbl,
MAX(
($A3=partsTbl)*
(B$2>DATE(YEAR(partsTbl[[Test Start Date]:[Test Start Date]]),MONTH(partsTbl[[Test Start Date]:[Test Start Date]]),0))*
(B$2<DATE(YEAR(partsTbl[[Test Finish Date]:[Test Finish Date]]),MONTH(partsTbl[[Test Finish Date]:[Test Finish Date]])+1,1))*
ROW(partsTbl)-ROW(partsTbl[#Headers])),
1),
"")
$A3=partsTbl returns a 2D array like {FALSE,FALSE,TRUE,FALSE;FALSE,FALSE, …} to find the part number in the table
Since your start/finish dates in the partsTbl are not always at the beginning/end of the month, we need to convert them to such before we compare the dates in B2:F2
(B$2>DATE(YEAR(partsTbl[[Test Start Date]:[Test Start Date]]),MONTH(partsTbl[[Test Start Date]:[Test Start Date]]),0))
And similar for the end of the month.
We now have a 2D-array of {FALSE,FALSE,TRUE,FALSE...} where the TRUE matches the part number as filtered by the dates.
ROW(partsTbl) returns a matching array of the row numbers in the table (and we subtract the row number of the Header row to determine the row within the data).
When we do our multiplication, we then get an array where the largest value will be the desired row
INDEX, referencing column 1, will then return the appropriate Plant #
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)
I have the following formula to return the value of the last value in a column:
=LOOKUP(2,1/(D:D<>""),D:D)
What I need now is to return the value of the cell adjacent to it as well. (It will not necessarily be the last value in that column and the info in Column D could have duplicates.
If your data looks like this:
A 1
A 2
A 3
B 4
B 5
B 6
C 7
To get last value this will do the trick:
=INDIRECT("B"&COUNTA(A:A))
And to get last where value is A:
=INDIRECT("B"&MATCH("A",A1:A7,0)+COUNTIF(A1:A7,"A")-1)
Just use next column:
=LOOKUP(2,1/(D:D<>""),E:E)
Ok, So I have found an answer by playing around with array formulas.
The problem was that this is a stock control sheet where there are changes made at multiple times, each recorded in the next available row. There is always a date (Column E) but not necessarily a Supplier, as it might be stock moving out. When a Supplier delivers, the Supplier name is recorded in Column D. In D1 the last supplier is then shown with the following formula.
=LOOKUP(2,1/(D:D<>""),D:D)
I want to then see what date it was last received. The formula I found that works is as follows (Array Formula):
=INDEX(E:E,MAX(IF(D:D=D1,ROW(D:D)-ROW(INDEX(D:D,1,1))+1)))
This is generally how I do it:
=XMATCH(FALSE,ISBLANK(A:A),0,-1)
This is what each part does:
Parameter
Explanation
FALSE
Instructs Excel to find the first instance of FALSE that it finds
ISBLANK(A:A)
Takes in the column A:A and notionally assigns a value to every item in the column
0
Means we want an exact match. Probably not necessary to put in, but I think it's good practice anyway
-1
Instructs Excel to start the search at the bottom/right of the range and work up/left. If you change this to 1 (the default), Excel will begin the search at the top/left and work down/right
So, taken together, this will search from the bottom of the column A:A, until Excel finds the first cell that is not blank, and return that cell.
Also, yes, this equation can be changed to a row format (e.g. 1:1), and can take a smaller range (e.g. A1:A20), but it cannot take a 2-dimensional range (e.g. A1:B20).
As a practical matter, this approach is much faster than other approaches (and much faster than you'd think, given it's evaluating against every row/column in the range), and won't get fooled by columns that have empty spaces in them (like with a COUNTA style approach).
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).