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.
Related
I'm trying to get a unique count of data in Column B that fall into the month of June (Column A date field)
Screenshot of Spreadsheet
I highlighted the rows that fall within June in Orange and the duplicate data in red to make it easier to view.
Count Total formula is a simple:
=COUNTA(A:A)-1
Unique Data formula is:
=SUMPRODUCT(1/COUNTIF(B2:B21,B2:B21))
Count June formula is:
=COUNTIFS(A:A,">=01/06/2020",A:A,"<30/6/2020")
But I can't figure out how get a count of unique data that falls within June (expected result is 13)
I've tried filter/unique formulas based on
Excel - Count unique values that meets multiple criteria
But I just can't get it to work. I know I could do it with VBA but this is part of a larger spreadsheet and every other part of the spreadsheet I've been able to do with Formulas, so would like to be able to do this last part with formulas too.
Anyone can help will be a life saver, it's been driving me nuts for the last couple hours.
In Excel 2016, which does not have the UNIQUE or FILTER functions, you can use this somewhat convoluted formula for a Unique count of June entries:
=SUM(IF(FREQUENCY(IF(LEN(IF(MONTH(Table1[Date])=6,Table1[Data],""))>0,MATCH(IF(MONTH(Table1[Date])=6,Table1[Data],""),IF(MONTH(Table1[Date])=6,Table1[Data],""),0),""),IF(LEN(IF(MONTH(Table1[Date])=6,Table1[Data],""))>0,MATCH(IF(MONTH(Table1[Date])=6,Table1[Data],""),IF(MONTH(Table1[Date])=6,Table1[Data],""),0),""))>0,1))
This part of the formula: IF(MONTH(Table1[Date])=6,Table1[Data],"") returns an array consisting of all of the June Data entries.
The LEN(... eliminates the resultant blanks
The Frequency function will then have us wind up with a count of 1 for each entry.
Then we just add it up.
Note that I used a Table and structured references, but you can convert it to regular addressing if you need to.
Of course, if you had Excel O365, you could use the simpler:
=COUNTA(UNIQUE(FILTER(Table1[Data],MONTH(Table1[Date])=6)))
I have a historical data set for commodity pricing. Throughout the data set, the data starts inputting prices on specific days, rather than the average of the entire month. In order to keep the flow of having only the average pricing for the months.
In the best case scenario, I would use an Averageif function, however, the data for each month doesn't display a consistent amount of days.
How can I automate this the process: If the month is the same as the previous row and different than the next row, calculate the average of the ^ rows until you hit the next month.
Here's a simple display of what I mean:
]1
You can use a pivot table to get the output you want. It will also be neatly organized instead of having your averages mixed in with a mostly blank column. Photo below shows the set-up/output of a pivot table generated with random data.
For a solution without pivot tables, you can use the following formula :
=AVERAGEIFS($B$1:$B$30;$A$1:$A$30;">="&(A1-DAY(A1)+1);$A$1:$A$30;"<="&EOMONTH(A1;0))
The above example is from cell C1, and can be copied down the entire list. The dates are in $A$1:$A$30 and the values in $B$1:$B$30. The first conditions test on the first day of the month (calculated as A1-DAY(A1)+1),and the second condition as last day of the month (calculated as EOMONTH(A1;0)
This will obviously put the average value of the month on each row, but will also work if your data is not sorted on date. If this is the case, and you only want to display one number per month in the column (as in your own example), you can add an additional IF statement wrapped around the formula:
=IF(EOMONTH(A2;0)=EOMONTH(A1;0);"";AVERAGEIFS($B$1:$B$30;$A$1:$A$30;">="&(A1-DAY(A1)+1);$A$1:$A$30;"<="&EOMONTH(A1;0)))
So it will display empty in all cells, except where the month changes.
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).
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.
I am extracting data from an account statement which you can see simplified in the image in the columns A:B in red:
On A the date (in order ascending but not necessarily incremental by one) and often duplicated due to multiple account entries) and on B the fund value.
If there are days missing, the fund value is the one of the last displayed day
=> I need to for each row on C, the average of fund since the first entry of the series (January 1st).
I can do it easily if I bring to a sequential order the fund values as I did in columns G:H but I would like to avoid this method and find a formula that placed in columnC gives me the average value. Possibly no VBA
Thanks
----ADDED---
the result I would like to see and the file example
http://www.filedropper.com/example_29
How about the following formula:
=(IF(DAY(A3)-DAY(A2)>=1,(C2*DAY(A2)+B3+((DAY(A3)-DAY(A2)-1)*B2))/DAY(A3),C2))
Note that the dates need to be in subsequent order and field C2 needs to be hard-coded for my solution to work.