Selecting a range based on the reference of one cell - excel

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).

Related

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")

Excel - SUM Daily results based on given date range

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.

How to sum data in a column corresponding to a start date to today's date

So, I am working on a loan payoff sheet and I wanted my excel sheet to be automatically updating.
One of my questions was answered when I searched how to select data corresponding to today's date using the function VLOOKUP(TODAY(),A:B,2,0) but that will only respond data in the column adjacent to today's date.
I would like to sum the data in the column of daily interest from the start date (provided) and have it automatically update for today's date. Attached is a snapshot of what I am trying to describe.
I currently have the dates stretched out several months in the future and am just summing the entire column of daily interest values.
If anyone knows how I can choose a start date of the first day and then automatically sum the values of the dates in between that would be fantastic.
Assuming Column A is your Date column and its the only numbers in the column you can use:
=MIN(A:A)
Having said that normally charts like this are built by a start date provided in a cell somewhere. If you can find that cell, simply link to it instead.
In order to get your sum of only appropriate dates, you will want to look at the formula SUMIFS. This will allow you to have multiple criteria that all have to be true. Assuming your interest is in column C you might be able to use the following formula:
=SUMIFS(C:C,A:A,">="&MIN(A:A),A:A,"<="&TODAY())
'Substitute your direct cell link for MIN(A:A) if you have it
Basically
=SUMIFS(Range to sum, range to check 1, criteria for check 1, range to check 2, criteria for check 2)
If for some reason you have data above and below your dates and interest column, you may need to adjust your ranges from A:A to A5:A678 where 5 is the first row of your data and 678 is the last row of your data.
With dates in column A and value in column B, place the start date in C1 and the formula:
=TODAY()
in C2. Then in another cell enter:
=SUMPRODUCT(--(A1:A9999<C2)*(A1:A9999>C1)*B1:B9999)
This formula give the sum of values between the date limits (not including).
The formula does not require the dates in column A to be in sorted order.

Excel using COUNTIFS Function to create a Punchcard

In my data source I have a column that contains the Dates of occurrences and a Column that contains the Hour of the same occurrences.
With this, the goal is to obtain a punchcard plot (maybe the bubble chart will be the most appropriate)
The intermediate structure has the weekday(Sunday-Saturday) as rows (A2:A8), and the hours (8-22) as Columns (B1:P1), as each column must have the occurrence count for a week day in an hour.
With this said, I tried to use the COUNTIFS function, using the following approach, for the cell B2:
=COUNTIFS(WEEKDAY(RawData!T2:T9852;1);A2;HOUR(RawData!U2:U9852);B1)
However, Excel is not computing the value, finding a problem on the formula, having also tried using the Insert Formula Option.
place the following in B2
=SUMPRODUCT((WEEKDAY($T$2:$T$8,1)=WEEKDAY($A2,1))*(HOUR($U$2:$U$8)=HOUR(B$1)))
you will need to convert the , to match the ; on your system
In your range A2:A8 enter a known date for monday such as 2017/08/20. Then select A2:A8 and apply custom formatting for the number format and set it to ddd. This will display the day of the week in text but keep the value in the cell a number.
Adjust the ranges to suit your data.
Copy the formula to fill in your table.

Countif with dynamic headers

Good afternoon! I'm trying to get a Countifs or Index Match statement to count the number of times a value occurs in another table. The example:
On my report sheet, Column A contains 10 different statuses, such as Green, Yellow, Red etc.; Row 1 contains six dates, such as 1/31/2015, 2/28/2015, etc. These dates are calculations. The last date references my date worksheet and the five other use EOMONTH to get the month end for the five prior months.
On my data table, I have 7 descriptive columns (such as Type, Make, Model, etc) and then we begin date columns: 1/31/2010 all the way to 7/31/2015. I add a new column each month (I know, I don't like it either, but unfortunately we don't have a time series database).
What I need to do is have a Countifs or Index Match that pulls the date from my report tab, goes and finds it in the header row of my tblTrends, and then counts all those statuses that are Green, and if it's a SUV (for example).
Thoughts?
Thx!!
G
At it's most basic, you'd want something akin to:
=COUNTIFS(TypeRange,"SUV",FirstMonth,Status)
So let's say your data table starts in column L, and the first date column is O:
=COUNTIFS($L$1:$L$100,"SUV",O$1:O$100,A$2)
As you drag this formula across the different dates, it will move the date reference over one to the next month.
If you need it to dynamically determine the date column, I'd recommend OFFSET, which dynamically select a range. However, note that OFFSET is a "volatile" formula, which means it re-calculates anytime a change is made anywhere in the file, which can lead to pretty slow load times if not used sparingly.
=COUNTIFS($L$2:$L$100,"SUV",OFFSET($N$2:$N$100,,MATCH(B$1,$O$1:$Z$1,0)),$A2)
The OFFSET starts on column N, because that's the first column before the columns we want (the date columns). The MATCH tells it how many columns to OFFSET from here.
If you're going to use this over a large amount of data, then you could avoid using the OFFSET formula by creating a dynamic table. This table would only contain data for the six months you're interested in, by utilizing INDEX/MATCH, and you could run your COUNTIFS off this table, instead, using the original, basic method I first described. I can go into detail if you're unsure what I mean.

Resources