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

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

Related

Formula for if a cell is blank, It will consider the previous cell as the value for that cell and sum the cells together

I am trying to figure out how to sum a row of cells where if a cell in the row has a letter, for example a letter "X", to consider the cell to the left of it in the row as a value for that cell when summing up the row. For my table the reason behind this is I have a table that is for a construction project work week where each day I list the amount of employees work that day. On their off day I still need to consider them for when I sum the project up and pay for their hotel on the days they don't work. Also the employee count per day can change throughout the duration of the project. Example of this bellow:
A B C D E F G H
5 5 5 5 4 4 X 4
So for this A through G is considered Monday-Saturday. Monday-Thursday I have 5 employees, while on Friday-Sunday I will have 4 Employees even though the 4 employees didn't work on Sunday for their off day I still need to sum the week up to charge a daily hotel price since the 4 employees will come back the next monday, which is "H" above and continue to work.
So is there a formula where I if I am summing up the row and it finds an X then it will sum the previous cell two times? And I do not want to add employees to the Sunday column because I have another formula that sums the work days to charge their hourly pay rate.
Enter this array formula in next cell ( with ctrl shift enter )
=SUM(IF(COLUMN(A1:H1)<=COLUMNS(B1:H1),NOT(ISNUMBER(B1:H1)))*(IF(ISNUMBER(A1:H1),A1:H1,0)))+SUM(A1:H1)
Obviously it won't consider if first cell contains an X. Rest in any of the cell if X is there, it will add up the previous value twice
Moreover it'll work if cell contains any numeric character
If it's always about the Sunday containing an X or not then I guess this is what you mean:
=IF(G2="X",SUM(A2:F2)+F2,SUM(A2:G2))

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 calculate the daywise average and multiply it to number of rows in that particular day

I have daywise excel data of four months which contains hourly data from 10 AM to 3 PM or sometimes 10 AM to 2 PM....1PM ..... like wise it is varying. The column A contains the date, Column B contains the time and column C and D has the data which i want to average for each day and multiply it to the number of occurrence.
For example If I have a data in column C and D for 17 Oct from 10 AM to 3PM (6 Hours)..Then i want to average these hourly data for a day and multiply it by 6. Since my interval of hourly data is not fixed, that is why i want a code which can average the daywise data and multiply it to the number of occurrence. I want to average the data 1 and data 2 for each day and to multiply its average by the number of occurrence of data in that particular day
I could not exactly get what does "average these hourly data" means since Average basically means summing all data within a day and dividing them to the occurrences. If you again multiply by the number of daily occurrence, you will get the summed value again.
Apart from above unclear point, un-merging all column B cells and filling all your rows with date data will be very helpful in order to form a quick sum or average formula based on the date conditions.
After doing above step, you may enter the below formula to E2 to get the sum of Col:C, for all data dated A2; 17-Oct.
=SUMIFS(C:C,A:A,A2)
And you may get the occurences on the date of your row data, you should use the formula and copy down:
=COUNTIFS(A:A,A2)
In combination of above 2 formulas, you may calculate the averages and/or date occurrences. I may write an exact solution if you may enter your requested values into COL:E and provide a screenshot.

Conditional Sum (based on current week)

I have an excel 2010 Workbook. Within this there are two columns.
The first column represents numerical week 1 (1-52 rows), the second contains a numeric value (never blank)
I would like a formula which basically sums all the rows (2nd column) up until the current week. So today it would sum the rows 1 through 11, next week it would sum 1 through 12
Tried a SUMIF but could not get it working (always zero)
Try this:
=SUMIF(A1:A52,"<="&WEEKNUM(TODAY(),2),B1:B52)
Where your week numbers run from A1:A52 and your values run from B1:B52.
You can also define which day the week begins on within the WEEKNUM() function by changing the second parameter. It is currently set to 2 which is based on the week beginning on Monday.

Excel - how to get if a date is a specific day of the week?

I have a spreadsheet that tracks average file processing times over the course of a month. One of the macros and stats that we like to pull, is performance on Mondays (as the files are a little built up over the weekend). The spreadsheet is organized into columns by weekdays of the month:
The dates are formatted MM/DD/YYYY, so I would think Excel has a date function that it can determine weekday based on that date value.
Currently, I just have to manually tell the Macro which columns are Mondays, like so:
=AVERAGE(B20,G20,L20,Q20)
So, instead of manually, how would I get the average over the range of say, B20 to V20, only if the day of the week is Monday (the date cells are in row 1, so B1 to V1)?
To determine the weekday of a date in EXCEL use the =WEEKDAY() formula, which evaluates as 1 (Sunday) to 7 (Saturday)
e.g. If A1 contains 12/31/2016 (or 31/12/2016 if you're from where I'm from), the formual =WEEKDAY(A1) would evaluate to 7 (indicating that the last day of 2016 was a Saturday)
To apply this formula to your problem: (assuming that the dates are in row 1 and the values are in row 2)
insert a new row to hold the WEEKDAY() value (say, row 2)
in cell A2 type in =WEEKDAY(A1)
copy this formula as far right as necessary (to include all your dates)
Your average for Mondays is calculated as =AVERAGEIF(2:2, 2, 3:3)
Possibly, you can add a column called [Day Of The Week] and use the following formula to display the day.
TEXT(B4,"dddd")
Then add an 'If'statement to your result cell.
simply
=SUMPRODUCT((MOD(B1:V1,7)=2)*B20:V20)/SUMPRODUCT((MOD(B1:V1,7)=2)*1)
should give the average of all values from B20 to V20 if the corresponding cell in row 1 is a monday.
the first part sums the values of all mondays and the second part counts them (sum / count = average) ;)
If you have any questions, just ask.
If your date is in A1, you can use =Text(A1,"dddd") to determine the day of the week (it will return the name, "Monday", "Tuesday", etc.) so then you could do perhaps:
=If(text(A1,"dddd")="Monday",[do whatever],[do whatever]) (may need a helper row/column to hold the text of the weekday)
(Or use AverageIf() and use the Text() idea.)

Resources