Excel - counting how many consecutive 0s in a row - excel

I have multiple ‘people’ in rows in excel, with 10+ columns of system usage data. I want the final column to show how many consecutive months have 0 usage. For example, person a might have had 0 usage in March and April, used in June, then 0 usage in July - December, I would need the end column to show 6.

If your data is from B2 to M2 you could use the following formula:
=MAX(FREQUENCY(IF(B2:M2=0,COLUMN(B2:M2)),IF(B2:M2<>0,COLUMN(B2:M2))))
This will show the max number of consecutive 0's in that row 2 from column B to M.
Older versions of Excel require this array formula entered with ctrl+shift+enter
If you want the formula to show the quantity of consecutive zeroes of the last occurance in the row then you could use:
=LOOKUP(2,1/(FREQUENCY(IF($B2:$M2=0,COLUMN($B2:$M2)),IF($B2:$M2<>0,COLUMN($B2:$M2)))>0),FREQUENCY(IF($B2:$M2=0,COLUMN($B2:$M2)),IF($B2:$M2<>0,COLUMN($B2:$M2))))

I've made something for you, based on the numbers of the months in the year: 1-12 (in column "item").
In the "Value" column, there are the values zero or else.
The "Length" column contains the number of subsequent zeroes, based on following formulas:
First entry : =IF(B2=0,1,0)
Following entries: =IF(B3=0,C2+1,0)
Screenshot:
Have fun!

This might help if 2 is threshold for consecutive in F3:AI3
=SUM((FREQUENCY(IF(F3:AI3>=0,COLUMN(F3:AI3)),IF(F3:AI3<0,COLUMN(F3:AI3)))>=2)*1)
suppose I want count of values more than 10 in groups of 5 and more then
=SUM((FREQUENCY(IF(F3:AI3>=10,COLUMN(F3:AI3)),IF(F3:AI3<10,COLUMN(F3:AI3)))>=5)*1)
hope this helps

Related

Excel... Sum a row of values based on a character in the value

I have 31 columns representing each day of the month. I have 2 housekeepers cleaning rooms. The rows represent the villa numbers from 1 to 18.
Housekeeper #1's name starts with "A" and housekeeper #2's name starts with "L"
I need to total the number of cleaning hours for housekeeper #1 in column AG and housekeeper #2 in column AH. The hours spent cleaning is a digit on the right side of the name.
The cells go across a row from B5:AF5 and look like this
Ann4__Ann3__Ann7__Lisa2__Lisa4__Ann4__Lisa1
For the "Ann" hours totals in AG5 I have tried using SUMIFS with this formula
=SUMIFS(right(B5:AF5),left(B5:AF5),"A") but Excel returns an error.
I also tried SUMIF for the number of hours for Ann
=SUMIF(LEFT(B5:AF5),"A","(RIGHT(B5:AF5)*1)) Excel still says error.
The hours digit after each name is text, so I tried multiplying the result by 1 to convert to numeric.
For Ann:=SUM(IF(LEFT(A1:D1,3)="ANN",RIGHT(A1:D1,1)*1,"")). For Lisa:=SUM(IF(LEFT(A1:D1,4)="Lisa",RIGHT(A1:D1,1)*1,"")). Both are Array entered with Ctrl+Shift+Enter

Count the number of full weekends worked (Sat&Sun) in an excel shift-work roster for each staff member over the current calendar year

I have an Excel rostering spreadsheet for shift workers and need to count the number of full weekends rostered (Sat&Sun) on/off for each staff member over the current calendar year.
I have tried several formulae, tried named ranges, countif, countifs etc. but am having problems counting identical values in two consecutive columns (days) in the same row i.e. Saturday and Sunday. Single day counts (such as number of Sundays worked) is no problem but I'm stumped with how to calculate the number of weekends when both days are rest-days, for example
The following works well for the number of single Rest Days (RD) falling on a Sunday but I need to determine the number of weekends in which both days(sat & Sun) are Rest Days.
=SUM(COUNTIFS(ROSTER!$M$17:$PM$17,"Sun",ROSTER!M28:PM28,{"RD"}))
The above is a small sample taken from a worksheet that contains a complete year's roster. Each roster is a two week block,starting on Sunday, with a column titled "RDFN" between the Sat and Sun at the end and beginning of the next fortnight.
Edit 2
As confirmed you want to count the number of weekends where both Sat and Sun are RD (Rest Day) in a given time frame.
I have revised my SUMPRODUCT formula (which works as COUNTIF in this case) to find the result for Jane. Simply drag it down to apply to other employees:
=SUMPRODUCT(((B5:AH5&C5:AI5)="RDRD")*((B$2:AH$2&C$2:AI$2)="SatSun"))+SUMPRODUCT(((B5:AH5&E5:AK5)="RDRD")*((B$2:AH$2&E$2:AK$2)="SatSun"))
This formula is using two SUMPRODUCT formula and adding the results from the two. Both SUMPRODUCT formula followed the same logic.
It will work in the case you have two columns between each fortnight, and it is actually slightly shorter than my previous
solution.
Let's take Jane's data for example. Imagine you have inserted four helper rows.
The formulas in the first helper row are B$2&C$2, C$2&D$2, and so on so forth till AF2&AG2, which represents SunMon, MonTue, TueWed, etc.
The formulas in the second helper row are B5&C5, C5&D5, and so on so forth till AF5&AG5, which represents RD8 M, 8 M14 A, 14 A14 A, etc.
So the first SUMPRODUCT formula is counting the number of RDRD in the second helper row when the corresponding position in the first helper row is returning SatSun.
First Part =SUMPRODUCT(((B5:AH5&C5:AI5)="RDRD")*((B$2:AH$2&C$2:AI$2)="SatSun"))
However the above formula is not working in situation where the last Sat of the first fortnight and the first Sun of the following fortnight are both RD because there are two columns in between which will not return RDRD in the second helper row so the match will fail.
To overcome the problem, I have to use a second SUMPRODUCT formula with the help from another two imaginary helper rows.
The formulas in the third helper row are B$2&E$2, C$2&F$2, and so on so forth till AF$2&AI$2, which represents SunWed, MonThu, TueFri, etc.
The formulas in the forth helper row are B5&E5, C5&F5, and so on so forth till AF5&AI5, which represents RD14 A, 8 M9 M, 14 A6 M, etc.
The second SUMPRODUCT formula is also counting RDRD in the forth helper row when the corresponding position in the third helper row is returning SatSun.
Second Part =SUMPRODUCT(((B5:AH5&E5:AK5)="RDRD")*((B$2:AH$2&E$2:AK$2)="SatSun"))
Adding the results from both parts will give you the total number of weekends where both Sat and Sun are RD as shown below:

How to create a dynamic formula to find the average of a set of values for a given vector

I am trying to create a formula that gives me the average of the last 12 entries in a given dataset depending on the associated vector.
Let's make an example:
I have in column F2,G2,H2 and I2 dates, Company1, Company2 and Company3 respectively. Then from row3 to row 33 I have months dates starting from May 2016.
Date Company1 Company2 Company3
May-16 2,453,845
Jun-16 13,099,823
Jul-16 14,159,037
Aug-16 38,589,050 8,866,101
Sep-16 63,290,285 13,242,522
Oct-16 94,005,364 14,841,793
Nov-16 123,774,792 7,903,600 41,489,883
Dec-16 93,355,037 12,449,604 69,117,105
Jan-17 47,869,982 13,830,712 83,913,764
Feb-17 77,109,905 10,361,555 68,176,643
The goal is to create a formula that, when I drag it down, correctly calculates the average of the last 12 values for a given company.
So for example i would have, say in table "B2:C5":
Company1 76,856,345
Company2 11,120,859
Company3 65,674,349
And, if a new Company4 is added to the list, then I just have to drag it down the formula, to calculate the average of the last 12 months for Company4.
Until now, I have came up with this formula:
=AVERAGE(LOOKUP(LARGE(IF(ISNUMBER(G:G),ROW(G:G)),ROW(INDIRECT("1:"&MIN(12,COUNT(G:G))))),ROW(G:G),G:G ))
This formula correctly calculates the average of a given column, considering only the last 12 values. The last step would be to come up with a formula that includes all the columns and then calculates the average for the given company.
Thanks!
I recommend that you use a named range to define your data in columns G:I. When a company is added, just modify the named range's specs. I used the name Target. Of course, you can replace it with $G:$I if you feel so inclined but I would rather recommend reducing the number of rows in the range, which is easier to manage when it is named.
Use the formula below to extract the company names from the first row of Target into the first column of your averages table. This is to ensure that the names are spelled identically in both locations.
=INDEX(Target,1,ROW()-2)
The number 2 indicates the number of rows above the row containing the formula. it is copied here from cell M3. There, ROW()-2 creates the number 1, counting sequentially as the formula is copied down.
Now I have the formula below in my cell N3 and copied down.
=SUM(INDEX(Target,0,MATCH($M3,INDEX(Target,1,0),0)))
The formula simply sums up the columns G, H, and I in 3 consecutive rows.
In the final step I inserted the range definition established above, meaning excluding the SUM() function, into your existing formula.
=AVERAGE(LOOKUP(LARGE(IF(ISNUMBER(INDEX(Target,0,MATCH($M3,INDEX(Target,1,0),0))),ROW(INDEX(Target,0,MATCH($M3,INDEX(Target,1,0),0)))),ROW(INDIRECT("1:"&MIN(12,COUNT(INDEX(Target,0,MATCH($M3,INDEX(Target,1,0),0))))))),ROW(INDEX(Target,0,MATCH($M3,INDEX(Target,1,0),0))),INDEX(Target,0,MATCH($M3,INDEX(Target,1,0),0))))

sum assigned vlaues if sum for each value meets a specific criterion

in excel, I have two columns. one containing months of the year (in numbers) each month number occurring in different number of rows, and in the second column I have a duration of time for each row (in hours and minutes).
now I want to do the following job with an excel function in just one cell (the same job could be done using a table with 12 cells, each for one month but I want to pack it all in one cell):
1- for each month number, sum all cells in the second column (time) which have that month number in the adjacent cell (this could be done with a sumif )
2- if that sum is more than 4 hours then return one for that month else return zero (this step could be done with a formula like this: IF(R10>(--"4:00");1;"") )
3. in the end the numbers assigned to each month summed together.
thanks to everyone who helps
the picture below, shows the steps:
enter image description here
Try,
=SUM(--(SUMIFS(Table1[time],Table1[month],{1,2,3,4,5,6,7,8,9,10,11,12})>TIME(4,0,0)))

Sum values in a column based on date

I have written this function that will give me a monthly sum for two columns: one has the date of each order, one has the cost of each order.
=SUMIF($C$1:$C$1000,">="&DATE(2010,6,1),$D$1:$D$1000)-SUMIF($C$1:$C$1000,">="&DATE(2010,7,1),$D$1:$D$1000)
Using data like this:
8/16/10 17:00 7.99
8/16/10 14:25 7.99
8/15/10 22:42 7.99
I end up with a table like this:
May 998
June 968.28
July 1239.76
August 514.96
However, now I would like to do daily sums and using my way I have to hand edit each row.
How can I do this better in Excel?
Use a column to let each date be shown as month number; another column for day number:
A B C D
----- ----- ----------- --------
1 8 6 8/6/2010 12.70
2 8 7 8/7/2010 10.50
3 8 7 8/7/2010 7.10
4 8 9 8/9/2010 10.50
5 8 10 8/10/2010 15.00
The formula for A1 is =Month(C1)
The formula for B1 is =Day(C1)
For Month sums, put the month number next to each month:
E F G
----- ----- -------------
1 7 July $1,000,010
2 8 Aug $1,200,300
The formula for G1 is =SumIf($A$1:$A$100, E1, $D$1:$D$100). This is a portable formula; just copy it down.
Total for the day will be be a bit more complicated, but you can probably see how to do it.
Use pivot tables, it will definitely save you time. If you are using excel 2007+ use tables (structured references) to keep your table dynamic. However if you insist on using functions, go with Smandoli's suggestion. Again, if you are on 2007+ use SUMIFS, it's faster compared to SUMIF.
Following up on Niketya's answer, there's a good explanation of Pivot Tables here:
http://peltiertech.com/WordPress/grouping-by-date-in-a-pivot-table/
For Excel 2007 you'd create the Pivot Table, make your Date column a Row Label, your Amount column a value. You'd then right click on one of the row labels (ie a date), right click and select Group. You'd then get the option to group by day, month, etc.
Personally that's the way I'd go.
If you prefer formulae, Smandoli's answer would get you most of the way there. To be able to use Sumif by day, you'd add a column with a formula like:
=DATE(YEAR(C1), MONTH(C1), DAY(C1))
where column C contains your datetimes.
You can then use this in your sumif.
Add a column to your existing data to get rid of the hour:minute:second time stamp on each row:
=DATE(YEAR(A1), MONTH(A1), DAY(A1))
Extend this down the length of your data. Even easier: quit collecting the hh:mm:ss data if you don't need it. Assuming your date/time was in column A, and your value was in column B, you'd put the above formula in column C, and auto-extend it for all your data.
Now, in another column (let's say E), create a series of dates corresponding to each day of the specific month you're interested in. Just type the first date, (for example, 10/7/2016 in E1), and auto-extend. Then, in the cell next to the first date, F1, enter:
=SUMIF(C:C, E1, B:B )
autoextend the formula to cover every date in the month, and you're done. Begin at 1/1/2016, and auto-extend for the whole year if you like.
If the second row has the same pattern as the first row, you just need edit first row manually, then you position your mouse pointer to the bottom-right corner, in the mean time, press ctrl key to drag the cell down. the pattern should be copied automatically.

Resources