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

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

Related

Only show the sum of a column if there are at least 3 records in another column

I have 3 Columns of data. Column E = Duration. The user will enter a number of days (Duration) for 20 employees. Column F = Pay. List of wage for each employee. Column R = Pay Total. This is a calculated field based on the number of days (Duration) and the employees pay (Pay).
To keep my employees from finding out their coworkers pay I only want to see a sum for Column C if there are at least 3 records in Column A.
I found this Sum only if 3
From that answer I tried to use =IF(COUNTIF(E2:E15,">2"),SUM(R2:R15))
What this does is only returns records with a duration of greater than 2 days. I don't care about the number of days. I want the indicator to be that there are 3 cells populated in this column.
I think the only issue with the formula is the CountIF part. I need to know what I should use to count cells not days.
Screenshot of My Sheet
In the image above you can see that it's returning a sum bc both records are greater than 2. Like I said before I don't care what number is in the cell I just want to see the sum if there are more than 2 cells populated in that column.
Thanks for any help
As per my understanding of the question, I came up with this solution. Give it a try.
=IF(COUNT($E$2:$E$15)>2,SUM($R$2:$R$15), 0)
This formula would give what you want
=IF(COUNTA(E2:E15)>2,SUM(R2:R15),"")
This would show sum only if count of non empty cells is greater than 2 in Range "E2:E15" else it would show empty.

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:

Count cell per month

I look for a code for the number of times a value is in a cell, on a monthly basis
So
1-1-19 KS
2-1-19
3-1-19 KS
.
.
1-2-19 KS
2-2-19
3-2-19
January 2
February 1
is this possible?
Assume that your dates are in column A, your KS is in column B.
In cell D1:D12 you have the first of each month entered and given a custom number format of mmmm so it just shows January, February, etc.
The formula =MATCH($D1,$A:$A,0) will give the row number that the month starts on.
For simplicity I'll call this Start_Row.
The formula =MATCH(EOMONTH($D1,0),$A:$A,0) will give the row number that the month ends on.
I'll call this End_Row.
The formula INDEX($B:$B,Start_Row):INDEX($B:$B,End_Row) will set a reference in column B to all rows between the first of the month and the end of the month.
I'll call this CountRange.
Now you just need to count what's in that reference using either:
=COUNTIF(CountRange,"KS") to count just KS
=COUNTA(CountRange) to count any non-blank cells.
So the full formula, without any helper columns, would be:
=COUNTIF(INDEX($B:$B,MATCH($D1,$A:$A,0)):INDEX($B:$B,MATCH(EOMONTH($D1,0),$A:$A,0)),"KS")
Keeping in mind that D1 contains 01/01/2019

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

Excel function to calculate pairwise date difference

I have a excel sheet with all employees of my company. This list also includes the sick days of each employee. I want to calculate the sick days of each year.
My excel sheet looks like this (shortened version):
A B C D E F G ...
1 Name From To From To From To ...
2 Max 2015/06/15 2015/06/16 2016/08/17 2016/08/17
3 Sarah 2016/01/20 2016/01/20
4 Phil
...
Explanation: Max was sick for two times. First from 2015/06/15 to 2015/06/16 and second from 2016/08/17 to 2016/08/17. Every time he gets sick the table is expanded to the right. Sarah was sick only on 2016/01/20 and Phil wasn't sick.
Now, I want to calculate the sick days of a year.
I could do something like
A B
10 2015 Sum of sick days in 2015
11 2016 Sum of sick days in 2016
So what needs to be done is:
check if date is in the right year
pairwise calculation of networkdays of all dates in a row, that means
=SUM(NETWORKDAYS(B2;C2)) for 2015 and
=SUM(NETWORKDAYS(D2;E2);NETWORKDAYS(B3;C3)) for 2016.
But it should work more dynamically. I only want to choose the matrix, e.g. A1 to I8 for each year and the rest should be calculated automatically. Does anybody know how I can do that?
You can use the below formula. (paste this in the cell B10
=SUMPRODUCT((YEAR($B$2:$N$8)=$A10)*(MOD(COLUMN($B$2:$N$8),2)=0)*(($C$2:$O$8-$B$2:$N$8)+1))
Copy the above cell into B11. It should work.
The following seems quite unruly:
=IF(YEAR(C2)=A10,NETWORKDAYS(B2,C2))+IF(YEAR(G2)=A10,NETWORKDAYS(F2,G2))+IF(YEAR(K2)=A10,NETWORKDAYS(J2,K2))+IF(YEAR(C3)=A10,NETWORKDAYS(B3,C3))+IF(YEAR(G3)=A10,NETWORKDAYS(F3,G3))+IF(YEAR(K3)=A10,NETWORKDAYS(J3,K3))+IF(YEAR(C4)=A10,NETWORKDAYS(B4,C4))+IF(YEAR(G4)=A10,NETWORKDAYS(F4,G4))+IF(YEAR(K4)=A10,NETWORKDAYS(J4,K4))
Alternatively you could either write a macro to loop through the data or add an additional two columns in between each From and To column. D2 would be
=IF(ISBLANK(C2),"",YEAR(C2))
and copy down. E2 would be
=IF(ISBLANK(C2),"",NETWORKDAYS(B2,C2))
and copy down. E11 would be
=SUMIF(D2:D4,$A11,E2:E4)
and copy across to I11 and M11 etc. You can then just
=SUM(C11:M11)
These new columns can be hidden if you needed.

Resources