Adding numeric value based on tickbox in Sharepoint formula - sharepoint

I'm trying to create a simple leave planner application using Sharepoint. I've got the bulk of it working but I'm going back to do edge cases now like Bank Holidays and half days. So I've added a checkbox column and if ticked, I want it to deduct 0.5 from the total value (half-day). The formula that's working for the full days is:
=(DATEDIF(dateFrom,dateTo,"D"))-INT(DATEDIF(dateFrom,dateTo,"D")/7)*2-IF((WEEKDAY(dateTo)-WEEKDAY(dateFrom))<0,2,0)+1
So I just created another two columns called shalfday and ehalfday. If they're ticked then deduct 0.5 from the total (If dates match and both ticked then deduct 0.5 still).
I've tried playing round with things like
-IF([shalfday],"0.5")
and other variants as google results are not being too kind this morning but they're returning #NAME? variables.
Any pointers on the syntax or what I should be looking at?

I would suggest:
-IF([shalfday],0.5,0)
Since you are trying to subtract you should work with integers and not strings (i removed the quotation marks).

I ended up doing this another way. I instead asked the user to specify how many half days were in their leave in another site column and used this suffix in the formula. It also got rid of the validation check to make sure the user wasn't taking two half days on 1 days leave.
New site column called 'Total Half Days' set to number, default value of 0;
Appended to original formula:
-([Total Half Days]/2)+1
Full formula:
=(DATEDIF(dateFrom,dateTo,"D"))-INT(DATEDIF(dateFrom,dateTo,"D")/7)*2-IF((WEEKDAY(dateTo)-WEEKDAY(dateFrom))<0,2,0)-([Total Half Days]/2)+1

Related

Excel - How do I calculate sum of products bought in a period of time based on X lead days

I am creating a formula to try yo find the total amount in pounds that is in in-transit. The current lead time is 5 days. But I have placed a manual override where we could change the lead time to 10 days for example. How do I get it to change outcome to be similar to the 2nd picture below.
the equation in the first white cell is the following
=SUM(OFFSET(B1,0,0,5))
where 5 is the default lead time, but I would like to have that change depending on whether there is a value in the lead-times override (Final Column)
This equation is dragged down to the remaining white cells in this table so that the last white cell is
=SUM(OFFSET(B12,0,0,5))
Current Results
This is what I want it to look like
Desired results
Sorry if I am unclear in my question since, it is a bit hard to explain in writing.
Just check if the value exists and use it. If not, fall back to 5.
=SUM(OFFSET(B1,0,0,IF(NOT(ISBLANK($C$9)), $C$9, 5)))
Don't forget to make the override cell static (with the dollar signs) or they will shift when dragging your formula.

How to filter data of last record of each week

I have a big data set of daily selling value of a particular ITEM. I want to know what was the price of ITEM on the last day of each week. Typically the last working day is Friday but if you don't have data for Friday then we need to get the previous working day data (Thursday).
Monday is considered the First day of week.
My Data looks something like this:
Data is in cells A2:C13.
My expected output is shown below:
Please help with VB macro or even simple excel formula.
You may want to try using a formula using the LOOKUP function, to search the list from bottom to top.
Afterward, a combination of INDEX and MATCH may get you on the right path as well.
Edit: I realize now that I was leading you astray because I thought you were asking something else! The most straightforward way I can see is as follows:
use WEEKDAY() to pull out the weekday values (as you did), except leave the values as numbers (with 1 being Sunday and 7 being Saturday).
Check each of these days to see if it precedes (i.e. has a lesser value) than the day above it. If not, we know that the week started over, and that cell is the last day of the week. Therefore, display its value.
Of course, this assumes that there are no Saturdays in your data - otherwise, Saturday would be listed as the end of the week. If you're crafty you can fix this dilemma though!
Thanks, Tyler.
Your suggestion helped me a lot in putting efforts in the right direction.
The way I did is as follows:
First I sorted my data in decreasing order of date so that I can have all the latest data at the top.
Range("AW4:BE999999").Sort Key1:=Range("BC4:BC999999"), order1:=xlDescending, Header:=xlYes
From Date created a string of "YEAR"&"WEEKNUM". This way I was able to group all the days in a specific week. Formula Used is:
=(TEXT(BC5,"yyyy"))&(TEXT(WEEKNUM(BC5),"00"))
Then I gave a unique Number to each record. The best way I could think of is to give the row number where record belongs.
=ROW(AY5)
Now using VLOOKUP function I got all the records matching string I have created in step 2
=VLOOKUP(AZ5,AZ:BD,5,FALSE)
I applied the above formula to get all the columns that I need.
Now I removed all the duplicate rows using below formula:
Cells.RemoveDuplicates Columns:=Array(1)
Now the remaining rows are the expected rows.
There may be a better way to do this but this is my first time with excel macro and formulas, so feeling happy.
Please comment other better ways to do this. It's always good to keep on improving our work.

How to pull a random object from a list and remove it in Excel?

I'm trying to create a rotational schedule in Excel that will randomly assign a building once a week without duplicates. I need each building to have a morning/afternoon shift and alternate the following week.
So what I was thinking is there are 20 shifts every 2 weeks, Morning/Afternoon 5 days a week and I have 10 buildings to go to so that works out nicely. I want it to be random so that way I am not always in the same building at the same time every week.
So I used =RAND() in Column B of sheet 1 to generate a random number for each building and then pasted it as just values to get rid of the formula in that column.
Then on sheet 2, I tried having =INDEX(Sheet1!$A$2:$A$11, RANDBETWEEN(1,COUNTA(Sheet1!$B$2:$B$11))) in each cell of 5x4 schedule.
The problem is there are duplicates and I want the second week to actually be opposite morning/afternoon but still random days. I think that I'll probably have to have it randomize morning/afternoon the first week, then do days and the second week have it opposite whatever the random morning/afternoon was and then do random days again but I'm just not sure how to go about it.
I'm new to programming in Excel and my programming is a little rusty in general...
EDIT: I was able to use =CHOOSE(RANDBETWEEN(1,2),"Morning","Afternoon") to have a column choose morning/afternoon randomly but it doesn't ensure equal number of mornings to afternoons which I need. And I still wouldn't know how to have the opposite results elsewhere for the following week.
I think you can use if condition to make sure you select opposite morning/afternoon after you selected random days.
like this:
=IF(AND(B3="Morning",C3="Morning"),"Afternoon",IF(AND(B3="Afternoon",C3="Afternoon"),"Morning",C3))

Excel function for First Row and Last Row of group

I have a gate keeping report with a number of entry/exit times for an employee over a 24hr period.
I need another formula to go into I40 which is the difference between the first entry time - last entry time for each employee eg. I40 = F50 - D40.
Dont worry about the formula regarding the subtraction of dates as I have this. I really just need the formula that will allow me to get the Last Exit time cell and the First Entry time cell for each employee.
The best way is to always store datetime values (ie, 2018-05-24 13:454) instead of just the times. You could still display it as a time by changing the cell's formatting to a time format.
Shortcut to Number Formatting options: Ctrl+1
There are many advantages, including that "regular math" will still work even if a shift starts in a different day than it ends.
If you must stick with only times, you can still calculate it correctly (up to a 23.9-hour shift) with an IF statement to add a day if the returned value is negative.
For example, if your existing formula works for same-day shift, and is:
=F50-D40
...then you could change it to:
=IF(F50-D40<0,F50+1-D40,F50-D40)
More Information:
Office.com : How to use dates and times in Excel
Office.com : Add or subtract time (Excel)
EDIT:
Looking at your question again, perhaps I misunderstood what you were trying to ndo. It's a little unclear, but you mention the fist and last times.
If you mean the "earliest and latest", you can get those using MIN and MAX. If the crossing-midnight is an issue here too, you'll need to see my first suggestion above, or else add a "helper column" to determine which times are before which.
Storing datetime is still best and this all would have been avoided.
try the below to get the difference in hours.
=(E50+F50)-(C40+D40)

MS-Excel Negative times

I'm writing a spreadsheet for a shop manager. What it does is keep track of the number of hours a worker has worked.
So you enter times for Monday-Sunday, and then an adjustment - e.g. if they work 40/40/40/32 hours for the month, then you would have an adjustment of -2/-2/-2/+6 to bring the worker to the 38 hour week that he's being paid for. Some (most) weeks may be adjusted for overtime. The spreadsheet then totals the hours.
This spreadsheet is supposed to just be a self-calculating version of a paper form.
It needs to match the paper form as it has to be substituted for the old form which is given to some other member of the company (pay clerk, I don't know; I'm not rebuilding their whole system, just replacing a form)
I'm having trouble entering a negative time in the adj field - the field has a [h]:mm formatting. and when i enter a negative time (e.g. -2:00) it displays an error, saying "incorrectly formatted equation", with the suggestion that if I was entering a string then I should prefix with a apostrophe.
How do I overcome this?
Tools - Options - Calculation - 1904 date system
Check this box to use the 1904 (Mac) date system and you will be able to use negative dates and times. I'm not sure how this will effect existing spreadsheets, so maybe someone else can speak to that.
According to Excel...
"Dates and Times that are negative appear as ########"
Doesn't sound like you're going to be able to do that with an auto-summation formula. You'll have to set the formatting as none and just type it in (which defeats the purpose).
I am solving the same problem. Setting for date formatting "1904" is necessary for both below described solution.
You can enter an equation as a result of predeceasing cells like C5-C4-C3 (check out-check in-standard working time). The result is negative and it will be displayed like -1:15 and you can further process it.
Second way was already described above - to put into the requested cell a negative decimal value as a fraction of "1". "1,000"=24 hours, "0,5"=12 hours, "0,01"= 14 minutes, "0,041667"=1 hour. You have to find the correct decimal numbers first.

Resources