I am trying to count ¨"the number of stops during each month", and then place them in another table that contain the header as the months (Data Format).
I tried many formulas, in E5:
=COUNTIFS(A:A;"=GRP 1";MONTH(B:B);"=1")
=COUNTIFS(A:A;"=GRP 1";MONTH(B:B);=1)
=COUNTIFS(A:A;"=GRP 1";MONTH(B:B);"MONTH(E4)")
The error message is the following:
Any one has an idea?
Thanks
The criteria_range argument for the COUNTIFS function generally needs to be a range, and not an array. Hence your formula will fail.
You can use a Pivot table.
Drag the Group Number to the rows area
Drag Date of Stop to the Columns area
Drag Date of Stop to the Values area
Format as desired
For a formula solution, you can use SUMPRODUCT. You have to exclude the first row, or add an additional criteria as text entries will result in a #VALUE! error
E5: =SUMPRODUCT(($A$2:$A$200=$D5)*(MONTH($B$2:$B$200)=MONTH(E$4)))
Note that in your results table, the Date row are real dates formatted to show as they appear.
Or, if your data is in a table, you can use structured references.
=SUMPRODUCT((Table1[[Group Number]:[Group Number]]=$D5)*(MONTH(Table1[[Date of Stop]:[Date of Stop]])=MONTH(E$4)))
Edit:
As an exercise, it is possible to use whole column references, as shown in the formula below which tests to ensure that the column B entries are dates.
However, this will significantly increase calculation times, and is rather inefficient. You are much better off avoiding this by:
Excluding Row 1, or
Using a dynamic range reference, or
Using a Table with structured references
=SUMPRODUCT((IF(ISNUMBER(B:B),A:A,0)=$D5)*(MONTH(IF(ISNUMBER(B:B),B:B,0))=MONTH(E$4)))
Since this is an array formula, you need to "confirm" it by holding down ctrl + shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula as observed in the formula bar
New code.
Think we will have to use EDATE for this formula. For cell(E5) try the following.
=COUNTIFS($A:$A,"GRP "&RIGHT($D5,1),$B:$B,">="&E$4,$B:$B,"<"&EDATE(E$4,1))
Basically EDATE allows you to get the same date (e.g 1st of the month) as many months in advance a you need. In this case, we set EDATE to 1 month in advance.
Related
I'm struggling to write an excel formula using CountIfs that meet a certain criteria:
Criteria:
Filter by the week #
The line state must be "Down"
The duration must exceed 15 minutes
Must not count an incident twice if it happened in the same day
This is the formula I have so far:
=COUNTIFS('Raw Data'!A3:$A$1000000,'Tracker'!$B42,'Raw Data'!C3:C1000000, "Down", 'Raw Data'!E3:E1000000, ">=0.010417")
where 'Tracker'!B42 is the Week# I am searching for, and 0.010417 is the time conversion to 15 minutes.
This formula does work, but is counting events that happen in the same day twice. I am unsure how to filter for this.
Here is a reference table from my spreadsheet to help explain further:
For example, I want this formula to only count "Filler Capper" Reason on the 10/6 as one event instead of two. Any suggestions on how to do this?
I think the formula for counting the number of distinct dates based on 4 criteria is pretty ugly. I almost solved it but gave up. Using a pivot table is so much easier IMO. I don't know if this is reasonable solution for what you need, but you could easily summarize each week this way.
First I created a DateValue column, which is a numeric value of the date.
Cell C2 formula:
=DATEVALUE(MONTH(B2) & "/" & DAY(B2) & "/" & YEAR(B2))
Then I created a Duration_Flag column.
Cell G2 formula:
=IF(F2>=$J$1,"Yes","No")
Input the minimum duration in cell J1, then create a pivot table on columns A:G. While creating this pivot, select the "add this data to the data model" check box. This will allow you to count distinct.
After creating your pivot such as the design below, right-click on the DateValue cell (what you want to count), and then go to Value Field Settings. Scroll down to choose "distinct count".
I've a data set that shows;
employee name
date
time work started
time work ended
Now I am trying to have a report like sheet where I can select a certain employee name from a list of employees to view his/her time attended for a particular month.
I tried vlookup but went no where since I need to lookup by two columns plus a row.
Is this possible? without macros or vba.
Thanks
Since name and date are unique identifiers it is possible to use the sumifs function.
For ‘time in’ and ‘Rachel’ this will look as follows:
=Sumifs(column ‘time in’ from data set, column ‘name’ from dataset, “Rachel”, column ‘date’ from data set, “10/01/2017”)
Where Rachel and the date also can be a referenced cell.
=AGGREGATE(15,6,ROW(SHEET1!$A$2:$E$22)/((SHEET2!$B$1=SHEET1!$B$2:$B$22)*(SHEET2!$A4=SHEET1!$C$2:$C$22)),1)
The above formula will grab the row number that matches your criteria. to pull the information you want, you can place the row number inside an INDEX formula to get the following:
=INDEX(SHEET1!$D:$E,AGGREGATE(15,6,ROW(SHEET1!$A$2:$E$22)/((SHEET2!$B$1=SHEET1!$B$2:$B$22)*(SHEET2!$A4=SHEET1!$C$2:$C$22)),1),COLUMN(A1))
You can place the above in your first Time cell and copy right and down. You will see errors if criteria do not exist. ie no person of that name or no date data for that person. to avoid this you can wrap the whole thing in an IFERROR like the below:
=IFERROR(INDEX(SHEET1!$D:$E,AGGREGATE(15,6,ROW(SHEET1!$A$2:$E$22)/((SHEET2!$B$1=SHEET1!$B$2:$B$22)*(SHEET2!$A4=SHEET1!$C$2:$C$22)),1),COLUMN(A1)),"Nothing found")
if you would rather a blank than nothing found display change the "nothing found" to "" or 0 if you want 0 to be displayed.
Note: Aggregate is performing array like calculations in this case. As such you do not want to full column references as it will cause a lot of unnecessary calculations to be performed. Because you have unique entries, SUMIFS option given in another answer is a much better choice.
I think a pivot table will do the job for you.
Place the employee name in the filter, place date and
times in the rows.
Remove subtotals from the Pivot Table
Change Table layout to tabular and Repeat rows
Right click on the Time In and select Ungroup
Then you have the image below.
I have the following layout:
In B11 write this formula and drag down:
=INDEX($B$2:$E$5,MATCH($B$7&$A11,$B$2:$B$5&$C$2:$C$5,0),3)
In C11 write this and drag down:
=INDEX($B$2:$E$5,MATCH($B$7&$A11,$B$2:$B$5&$C$2:$C$5,0),4)
Note that these are Array-Formulas, so you need to enter them with CTRL + SHIFT + ENTER instead of the normal Enter.
You will get a #NV error if the employee hasn't worked on one of the dates A11 and A12. So you could surround the Formula with IFERROR to avoid this.
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.
As the title states, I am trying to count across cell ranges on a separate sheet but cant seem to get it to work. Any help would be greatly appreciated.
=COUNTIFS(MONTH(original!A2:A58),"1",original!D2:D58,"=East")
The issue is the Month() part in your formula. I understand your logic, but you'll have to probably add a new column on the Original sheet that has the month formula conversion there, then update the countif to reference it.
COUNTIFS(Original!monthcol, "1", Original!col, "East")
Again, in summary the Month formula can't do the conversion for an entire range of cells in the CountIf. The only other way would require an array formula. Hope this helps.
You cannot use the MONTH function as a form of sub-function in a COUNTIFS function. You need to add an extra level of calculation with something like a SUMPRODUCT function.
=SUMPRODUCT((MONTH(original!A2:A58)=1)*(original!D2:D58="East"))
That should count the instances where the month of the date in the Original worksheet's column A is January and the corresponding row's column D is East.
If you prefer to stay with a COUNTIFS and can keep the dates to a single year, you can provide a start date and end date which will bracket the month of January for a particular year.
=COUNTIFS(Original!A2:A58,">="&DATE(2015,1,1),Original!A2:A58,"<"&DATE(2015,2,1),Original!D2:D58,"East")
The default comparison operator for COUNTIFS is equals. There is no need to type it in.
So here are the Columns:
Column A: Date
Column B: Prices of NASDAQ
Column C: Prices of ABC Stocks
I want to run a financial beta formula, (=COVAR(C1:C1000,B1:B1000)/VAR(B1:B1000).
But, I don't want the cells to always start from the first row... I want to be able to calculate this formula at different rows.
For example, if I have (=COVAR(C60:C1000,B60:B1000)/VAR(B60:B1000)
I want to be able to make that change by referring to a date in a new cell labeled "Start Date" without rewriting each formula.
I'm thinking of nesting a =Cell("address") formula within a vlookup, but I'm having trouble with this.
Could anyone please help me?
INDEX is usually preferable to INDIRECT for 2 reasons
1.) INDIRECT is a "volatile" function which means that it re-calculates every time the worksheet changes - potentially slowing everything down
2.) With INDEX you don't need to "hardcode" the column letters like "C" so the formula will still work if you add or delete columns.
It would look like this
=COVAR(INDEX(C:C,MATCH(Date,A:A,0)):C1000,INDEX(B:B,MATCH(Date,A:A,0)):B1000)/VAR(INDEX(B:B,MATCH(Date,A:A,0)):B1000)
...or rather than repeating the same MATCH function 3 times you could put the MATCH part alone in a separate cell or make it a named range - e.g. named start and formula becomes:
=COVAR(INDEX(C:C,start):C1000,INDEX(B:B,start):B1000)/VAR(INDEX(B:B,start):B1000)