Excel - SUM Daily results based on given date range - excel

thank you for taking a minute to help me!
I have 3 sheets, 3 of them with daily data of users, vehicles, and population which is steady, all of them have the same structure:
D column is location and the rest are daily results. Results change every 14 days, that's why for each location you are seeing the same data.
And there's a 4th, where I want to concentrate results from the previous sheets based on data and location - location is D column:
I want to set both start and end date and based on that, sum daily results by location. For example, suppose that Inicio - Start date is 01/03/2020 and Termino - End Date is 05/03/2020, in the second image, where I highlight SUM HERE it should appear 227,340 for 001-L1 Dr. Galvez N.
I already tried SUMIF, SUMIFS, SUMPRODUCT but it doesn´t seem to work.
Any ideas?

What didn't work with SUMPRODUCT? Try this - the result is correct:
=SUMPRODUCT((Sheet1!$E$3:$M$3>=$E$2)*(Sheet1!$E$3:$M$3<=$F$2)*(Sheet1!$D$2:$D$14=D5)*Sheet1!$E$4:$M$14)
I tried to adjust the ranges to your example, but change them if necessary.

I have developed this formula for you (001). Please take a look.
[E5] =SUMIFS(INDEX(Counts1,MATCH($D5,Stops1,0),0),Dates1,">=" & $E$2,Dates1,"<=" & $F$2)
The formula is designed for cell E5 of your fourth sheet. $D5, $E$2 and $F$2 are all on this sheet.
Counts1 is a named range on Sheet1, comprising all the passenger counts, starting from column E, up to the last day of the month and, vertically, from row 4 to as many rows as there are stations.
Stops1 is another named range on Sheet1 D4:[end of column].
Dates1 is a third named range on Sheet1, starting from E2:[end of row]. I would suggest you set up these named ranges to adjust dynamically to the actually used areas of the sheet.
Now, INDEX(Counts,MATCH($D5,Stops,0),0) defines all cells in the row of Counts where the Stop is equal to D5. Of course, this reference changes as you copy the formula down.
SUMIFS takes that range, extracts and sums up the numbers you are interested in.
Now, if you need to extract the same numbers by the same system from 3 different sheets you simply repeat the formula 3 times, concatenating the results with plus signs. That leaves you with the task to set up 9 ranges instead of only 3, each group of 3 on one of your source sheets. By the system I have implied above you would name them Count2, Count3 etc.
That leaves the question of your dates. They must be true dates. Text strings that look like dates won't do. (I guess you know that :-). In the test sheet I set up I entered =DATE(2020,3,1) in E2, [F2]=E2+1 and copied from F2 to the right.

Related

How do I create a formula that will return a date where the sum of it and previous dates are greater than some requested number?

Example of Product Data and Inbounds
I have 20 products that I sell that each have some requested amount that people want to buy. I am struggling to figure out a formula by which I could have it return the week where the sum of it and previous weeks is greater than the amount requested, so I know on what week of inbounds the order can be fulfilled.
The example data only shows three columns of dates but in reality there could be up to 20 weeks of inbounds inventory, so it would be potentially a large series of sums before it finds the one greater than the amount requested. In the example image the cells highlighted in green are the correct week for each product that I manually marked.
Thanks for the help, I'm not sure where to even start on this.
Assuming that your table start in cell A1 (therefore the cell C2 value is 96), use this formula for your conditional formatting starting from cell C2:
=AND(SUM($C2:C2)>=$B2,SUM($B2:B2)-$B2<$B2)
Warning: the formula might stop working if the overall structure of the table is changed. For example: if columns with non-numeric data are inserted, the user will need to re-apply the conditional formatting. If said inserted columns will contain numeric value that are not meant to be sum in the formula, it won't suffice anymore.
I am afraid I don't have time to write a full answer but the below might help. I am sure there is a way to avoid writing multiple COUNTIFS with a SUMPRODUCT but I haven't got there yet.
=SUM(1,
COUNTIFS($B3,">"&$C3),
COUNTIFS($B3,">" & SUM($C3:$D3)),
COUNTIFS($B3,">" & SUM($C3:$E3))
)
This is a model built around your having 20 weeks so that you can have one formula which doesn't require continuous adjustment - it does require one column of helper cells for each week, though:
the helper cells start in column Y, where the formula in Y2 is
=SUM($C2:C2)
which is then copied to the right as far as column AR, and then copied down, one row for each of your products.
With all of the helper cells populated, the array formula in W2 is
=IFNA(INDEX($C$1:$V$1,MATCH(1,N((Y2:AR2-B2)>0),0)),"In the future")
which is then copied down, one row for each of your products.

Countifs for longer range

I am currently using Countifs to add up an amount of registrants that have a gender criteria and birth year criteria.
Formula:
=countifs(sheet1!N4:N90,”male”,sheet1!F4:F90,”1990”)
This works and shows me the amount of males born in 1990. I’m currently running this formula in sheet2. Every day or two I’ll import the registrations and the range will grow past row 90. Is there a way to write the formula that will adjust the result when I paste in new registrants?
Currently I can’t extend the formula past 90th row. And with all the birth years, it’s be great if I didn’t have to edit the formula manually every time I update the list.
There are at least 4 ways to do it:
Use "N:N" and "F:F" instead of "N4:N90" and "F4:F90". It will refers to the whole column.
Formula: =countifs(sheet1!N:N,”male”,sheet1!F:F,”1990”)
Use VBA (I'm not going to explain that now because I guess it's not what you want)
Use Dynamic Named Range like explained here https://www.excel-easy.com/examples/dynamic-named-range.html.
It applies to range without empty values (the height of the range is based on the number of values in the column and adding them to the row of the first row of your range (offset base).
We don't know how your registrant records on sheet1 look. I guess that on column A you have a record ID or something else that it's not empty until the table ends. While on column N and F you can have empty values (e.g. registrant year or gender is not mandatory).
So you have to create a named range 'Genders' that will refers to =OFFSET($N$1,0,0,COUNTA($A:$A),1) if you have not an header row. If you have one header row you have to start the offset from N2, etc. =OFFSET($N$2,0,0,COUNTA($A:$A),1).
You have to do the same thing for the birth year and use these named ranges in your formula, like:
Formula: =countifs(Genders,"male",BirthYears,"1990")
Convert the range of records to a table, selecting it and going to Insert-->Table. You'll be able to use table field names in the formula (Solution based on Ron Rosenfeld' comment)
=countifs(Table1[Gender],"male",Table1[BirthYear],"1990")

Selecting a range based on the reference of one cell

I have an excel file. I don't want to write any VBA code, as I don't necessarily want to run a macro for the process to work; I want it to automatically update information as I change one cell (the "Date" cell on the second sheet/photo).
So, basically I have a tracker that I will use to determine for any given date, how many tasks do I have issued to each company (military companies for context). It'll help me understand who has the least amount of tasks in general and what percentage of every company is dished out to tasks. I have a tracker of those issued tasks that looks like this:
My next tab looks like this:
It uses a COUNTIF (COUNTIF(all cells in that day's column on the first sheet/photo except the header, "Company's name")) to determine how many tasks any company has within that day; that's the "RAW" number. The "PERCENT" divides the "RAW" number by how many total people they have in the company; it already works as needed. My goal is to type in a date into the cell beneath "Date" and have the cells to the right of "RAW" automatically inform me for that date typed in. The "PERCENT" already does its magic.
I just don't know how to have the "RAW" cells' formula reference all cells underneath a date on the first sheet/photo after typing that date into "Date" on the second sheet/photo. I was considering an offset, but I'm not sure how to offset a range from the formula of another cell: A2:1000 if the formula of another cell [Date] references A1, and have those RAW cells reference change to DC2:1000 if that Date cells value or reference changes to DC1.
Use MATCH to find the date in the row of dates and insert this into OFFSET, as the COLUMNS argument, to say how many COLUMNS to the right you need to move, to count over the correct range for the selected date.
Say you had your selected date is in Sheet1!D2:
And your companies' tasks in sheet2, with the dates from column B1 onwards, and company HHC spans rows A2:A7:
You want to find the column containing the selected date using:
=MATCH(Sheet1!D2,Sheet2!1:1,0)-1) 'returns 9
The adjustment of minus one is that dates actually start in column B not A in row 1.
You know HHC spans Sheet2!A2:A7, in this example, and you now know you want to move 9 columns to the right of this to do your count.
Using OFFSET and the columns argument (9) yields Range J2:J7
OFFSET(Sheet2!A2:A7,,MATCH(Sheet1!D2,Sheet2!1:1,0)-1)
Inserting this into your COUNTIF, as the source range, with "HHC" as the criteria:
=COUNTIF(OFFSET(Sheet2!A2:A7,,MATCH(Sheet1!D2,Sheet2!1:1,0)-1),"HHC")
This is then the formula that would go in cell Sheet1!C1 next to RAW.
The same principles apply to your other companies. Define the start range for the company, use MATCH to determine the number of columns to OFFSET by, and then wrap it all in a COUNTIF.
A match being found depends on:
Date being present in search range;
That dates are of the same datatype in both sheets (i.e. dates in both sheets or strings in both sheets).

Sum values in different rows if they match

I need some help regarding an issue that I was not able to solve. I tried to figure it out but without reaching my goal. This is what I have:
In sheet 1 I have estimated active customers for a period of time, where columns are months and rows are departments/states:
Sheet 1
Then, in sheet 2, I'm forecasting sales and need excel to return values from sheet 1 depending on which month we are kicking-off for each department:
Sheet 2
Of course, the kick-off month may vary for each department and values from sheet 1 should accommodate according to the selected month on column B in sheet 2.
And within C2:I4 I have used this formula:
=IFERROR(IF(C$1>=$B2,INDEX(Sheet1!$B$2:$F$4,MATCH($A2,Sheet1!$A$2:$A$4,0),MONTH(C$1)-MONTH($B2)+1),""),"")
The formula above actually works great when departments are not repeated in sheet 1 but, what would happen if departments are repeated (as shown in sheet 1) and I have to sum values from the same department and show the result on each cell in sheet 2?
I look forward to your kind help!
Thanks!
Try using SUMIF like this:
=IFERROR(IF(C$1>=$B2,SUMIF(Sheet1!$A$2:$A$4,$A2,INDEX(Sheet1!$B$2:$F$4,0,MONTH(C$1)-MONTH($B2)+1)),""),"")
Please try this formula, designed for your Sheet2!C2 cell.
=IFERROR(SUMIF(INDEX(Rodrigo,,1),$A2,INDEX(Rodrigo,,MONTH(C$1)-MONTH($B2)+1)),"")
In order for this formula to work you should declare a named range comprising of your range Sheet1!A2:F4. My formula calls the range Rodrigo. If you choose another name please change the name in the formula accordingly.
You can exclude zero results by adding a further IF condition to the formula. I would prefer to do that via cell formatting, like 0;0;; where the third semi-colon determines that a zero will not be shown. You can also suppress display of zeros for the entire sheet in the worksheet options.

Need to select a range of cells based on a cell's value

Here is a little backstory on what I am trying to do. First, I am NO Excel expert by an means, but I am a rather quick study and have been able to figure out things as I go.
I created a daily tracking spreadsheet (that I should probably use Access for...) that tracks how many employees worked, type of work they did that day, who didn't work, etc. Most of the cells are color coded, contain specific text or numbers (a LOT of Conditional Formatting is also applied).
The code that I need help with is currently hard coded to look at a specific column and a specific range of cells. I need the code to be able to select the range of cells based on the current date, which is listed along the 3rd row from the top.
So instead of this: =IF(COUNTIF(Y4:Y61.... I need Y4:Y61 to be a formula that determines what cell the current date is in and calculate in that specific column's range of cells.
thanks in advance
Patrick
For COUNTIF() you could simply add the date column being for today as a criterion.
Assuming you want a more general approach you can use the OFFSET() formula as you can specify the position and size of the range.
Consider a sheet like this
A B
1 2015-10-27 1
2 2015-10-27 1
3 2015-10-28 1
4 2015-10-28 2
5 2015-10-28 1
6 2015-10-29 1
and today is the 28th of October
You can sum column B by using
=SUM(OFFSET(A1,
MATCH(TODAY(), A1:A6, 0),
1,
COUNTIF(A1:A6,TODAY())))
What this does is:
move the reference of A1 to the row where your entries from today start.
It then takes one column of width.
We then give it a row height being the number of entries for today making the formula return 4 today and 1 tomorrow.

Resources