Count if text appears in multiple columns in a row - excel

Essentially I am looking at a schedule and trying to figure out how many times a person worked a block - meaning their name will appear in columns side by side.
Each column represents a day of the week. So if John worked Mon - Tues that counts as a block and his name would appear in 2 columns. He then may work Thurs - Sat and that counts as a block. I need to figure out how often this occurs over the course of a month.
Manual counting using conditional formatting is one option - but I'd like to avoid it if possible.
Thanks for your help all, It is much appreciated!

For a solution in Excel, If John's schedule for the month is in row 2 (range B2:AF2), then try this for the number of blocks he worked (enter as an array formula with ctrl+shift+enter):
=SUM(--(IFERROR((B2:AF2="John")+(C2:AF2<>"John"),(AF2="John")+1)=2))
This assumes that if John worked a single day without working the day before or day after, it would still count as a block. Also, Note that if your schedule may contain error values (e.g., from being filled in with a formula), you'll need to wrap the schedule with IFERROR:
=SUM(--(IFERROR((IFERROR(B2:AF2,"")="John")+(IFERROR(C2:AF2,"")<>"John"),(AF2="John")+1)=2))

Related

Salary Calculation in Excel

So I have a problem that I'm dealing with for days now and I cant figure it out. I have this problem in excel, I am looking for assistance regarding a calculation. I want to be able to calculate a payment date schedule based on a set monthly payment date but to exclude exclude weekends and specific holiday dates e.g.
Here's My file I'm Working on:[].
Here is some function that I already used : =IF(TEXT(O2,"dddd")=$U$2,O2+2,IF(TEXT(O2,"dddd")=$U$3,O2+1,O2))This works for only weekends, It doesn't work on holidays, I want it to work not only on weekends and on holidays too.
Thanks in advance.
This can be done by using the WORKDAY() function together with the DATE() function.
B2 contains year - 2012
B3 contains payment day - 28
A5:A17 contain payment periods (month numbers) - 1..12
D6:D16 contain holidays
=WORKDAY(DATE($B$2,A6,$B$3-1),1,$D$6:$D$14)
Also see the linked image. (NB: My Excel version uses semi-colon ";" in stead of comma "," to separate arguments in functions.)
Best of luck!
Xharx
Image of the Excel sheet solution
Here's How u Do it. First we have to have starting month from where were gonna start counting I made this formula which works great, =WORKDAY(EDATE($B$15,COUNT($B$15:B17))-1,1,holiday1)
were freezing the starting date and counting how many rows are we from the starting position , then were gonna minus 1 from it , and in days were gonna type 1, if there's holidays that I wanna exclude too I just can enter it and give it a name, (Some of u who doesn't understand this, its just saying that its referring to specified cells which we named holidays) and it works flawlessly.
B15 = starting month

Look for a value a cell above

I'm looking for a formula or a VBA code for the following problem.
I need to get the total operational hours in a day (J). This is de difference from the start-up time (I) and the shutdown time (K) over the whole day.
Most of the entries are 2 a day, but as you can see in the picture this one has 4. Previously I had the formula in J : =IF(K49="";0;IF(EXACT(A49;A48);(K49-I48);(K49-I49))) But with 4 entries this does not work anymore (the A49 and A28 are just numbers if they are the same it means that it is the same day)
So where I'm basically looking for is that it will take the shut downtime and looks for the first value in I and that it is calculating the difference in J.
Referring to another cell can be done, using OffSet(Row, Col). In case you need the cell just above, you use OffSet(-1,0).
I would just use some nested IFs to check first the row above, then the one above that, then the one more above.
Something like this (sorry, I cannot embed images):
https://i.stack.imgur.com/XLHVO.png

Sum the number of days in one date range which fall within a second date range

I have two columns of dates. One is the move in date and the other the move out date. I want to figure out how many days the tenant was there during a second date range. for example: how many total "bed days" did we have in the month of July? 7/1/2016-7/31/2016
This function calculates the number of days each tenant was there each month but I would like it if I could get the entire calculation into one cell without creating a dummy column for each month.
=MAX(0,MIN(EOMONTH($B$2,0),I14)-MAX($B$2,H14))
I tried to change a few things and use it as an array function but it is not working. I am very new to array functions so I may be doing it completely wrong.
=SUM(MAX(0,MIN(EOMONTH($B$2,0),I:I)-MAX($B$2,H:H)))
any help is much appreciated! Let me know if you need more info too.
Bad news - you can't use MAX and MIN in an array formula like this because instead of treating H and I as two arrays it just treats them as one big long array and you only get one value out of them.
You also need to add 1 to your original formula because if they moved in on the last day of the month (say) it should still count as one day.
If you replace the MAX and MIN with IF statements you get something like this
=SUM(IF(IF(EOMONTH($B$2,0)<IF(I2:I10="Active",TODAY(),I2:I10),EOMONTH($B$2,0),IF(I2:I10="Active",TODAY(),I2:I10))-IF($B$2>H2:H10,$B$2,H2:H10)<0,0,
IF(EOMONTH($B$2,0)<IF(I2:I10="Active",TODAY(),I2:I10),EOMONTH($B$2,0),IF(I2:I10="Active",TODAY(),I2:I10))-IF($B$2>H2:H10,$B$2,H2:H10)+1))
which has to be entered using CtrlShiftEnter
A useful tip if you are new to arrays is not to include more rows in an array formula than you need to because it will be slow, and test it first on a small number of rows so that you can step through it using Evaluate Formula if you run into trouble.

Counting Number of Months between Two Dates in Excel

So I am attempting to simply count the number of months bewtween an earlier date and today, which will be in the B:B column; once the number of months have been counted, the result is then multiplied by 28, then added back to the original date. Note the requirement: Result >= Today, so basically if the result is less than today it needs to add another 28 days. The current formula I made only works if the dates are in the current year (and I am not 100% sure if this formula works, it appears to so far though.)
Here is my defunct formula, but maybe someone can get a general idea from my above comments and the below formula of what I am attempting to achieve here:
=IF(B89="","",IF(I89="X","LEG",IFERROR(IF((MONTH(TODAY()-B89)*28)+B89<TODAY(),(MONTH(TODAY()-B89)*28)+B89+28,(MONTH(TODAY()-B89)*28)+B89),"Future")))
Thank you in advance for your assistance!
Note: I just want to point out that the reference to I89 is insignificant in the above. I just didn't want to remove it in case I deleted the wrong parenthesis or some other typo, so I decided to leave in there. So basically you would not need to necessarily worry about the first two "IF" statements, nor the IFERROR, unless you just wanted to!
2ND EDIT: Okay I decided to strip down formula, original post's formula is above, the stripped version below:
IF((MONTH(TODAY()-B89)*28)+B89<TODAY(),(MONTH(TODAY()-B89)*28)+B89+28,(MONTH(TODAY()-B89)*28)+B89)
You should not use MONTH() for this purpose as this will lead to wrong results in some cases, and certainly when the B89 date is in another year.
Instead see how many days you are past the last multiple of 28 days since B89, and go back to that date (by subtracting), and then add another 28 to it:
=TODAY() + 28 - MOD((TODAY()-B89), 28)
The earliest date this can give is the date of tomorrow. If today should be an acceptable outcome of the formula, then replace TODAY() with TODAY()-1, which results in this formula:
=TODAY() + 27 - MOD((TODAY()-1-B89), 28)
How about something like this:
=IF(B89="","",IF(I89="X","LEG",IF(IF(B89<=TODAY(),B89+28*IF(AND(B89<TODAY(),TEXT(B89,"mmyy")=TEXT(TODAY(),"mmyy")),"1",(TEXT(TODAY(),"yy")*12+MONTH(TODAY()))-(TEXT(B89,"yy")*12+MONTH(B89))),"Future")<TODAY(),TODAY(),IF(B89<=TODAY(),B89+28*IF(AND(B89<TODAY(),TEXT(B89,"mmyy")=TEXT(TODAY(),"mmyy")),"1",(TEXT(TODAY(),"yy")*12+MONTH(TODAY()))-(TEXT(B89,"yy")*12+MONTH(B89)))))))
Got a little long now, but you have a lot of criteria :)

Excel Match function with concatenated value

I am somewhat new to writing large, complicated formulas with excel. I took over a report from someone about 7 months ago and it seems that every week I find issues with what was written with his formulas.
This week I am having issues with a match formula. We have a report we run for a big hardware store and they report based on weeks. This last week was 201501 (2015, week 1.) Last week was 201452 (2014, week 52.)
To look at 4 week sales averages, my predecessor setup 4 numbers that would change every week based on the week you type in one of the column headings. So, when I type 201452,
#1 is 201449
#2 is 201450
#3 is 201451
#4 is 201452
He feeds those into a match function.
I found this week that 201501 does not correctly display the weeks. I got
Results Formula Used
201501 =D1 (The cell where you type the Store's week)
201500 =IF(M1=201301,201252,IF(M1=201401,201352,M1-1))
201499 =IF(L1=201301,201252,IF(L1=201401,201352,L1-1))
201498 =IF(K1=201301,201252,IF(K1=201401,201352,K1-1))
I changed those formulas
Results New Formula
201501 =D1
201452 =IF(RIGHT(M1,2) = "01",(LEFT(M1,4) - 1)&"52",M1-1)
201451 =IF(RIGHT(L1,2) = "01",(LEFT(L1,4) - 1)&"52",L1-1)
201450 =IF(RIGHT(K1,2) = "01",(LEFT(K1,4) - 1)&"52",K1-1)
However, the match formulas he has setup throughout the workbook have not been fixed. They are still displaying "#N/A." One such formula is
=INDEX(N5:DZ5,1,MATCH(Data!$L$1,$N$1:$ED$1,0))
This formula basically looks at the column headers, and if it sees that the column header matches the week I've typed, will display the value within that range.
Basically, any formula that's being fed the 201452 value is returning "#N/A". The other numbers miraculously display data.
I've already tried converting all of my data in the affected rows to "General" format type. I've tried checking to see if I have spaces before or after in all of my formulas and column headers, but am still having no luck.
Any ideas?
After trying and trying and trying, I found that Excel does not like the concatenation. Trim does not help, Text does not help, Concatenate of course did not work.
I ended up realizing I could simply write
=IF(RIGHT(M1,2) = "01",M1-49,M1-1)
This makes it so that in the instance where the number to the right of it is the first week, subtract 49 days and produce 52 instead of 00.
I'm guessing here, but it could be that your formulas are presenting the Year/Week combo as a number, where the Match formula is looking for text (for Excel's purpose, it doesn't recognize them as the same).
You can get around this, by wrapping your formulas above with the text formula
So you'd have the following:
Results New Formula
201501 =TEXT(D1,"0")
201452 =TEXT(IF(RIGHT(M1,2) = "01",(LEFT(M1,4) - 1)&"52",M1-1),"0")
201451 =TEXT(IF(RIGHT(L1,2) = "01",(LEFT(L1,4) - 1)&"52",L1-1),"0")
201450 =TEXT(IF(RIGHT(K1,2) = "01",(LEFT(K1,4) - 1)&"52",K1-1),"0")

Resources