Would anyone be able to help me calculate the number of days between two dates excluding Sundays in Cognos? I would also like to count the next day as the first counted day. For example, if something was picked up on a Monday, the first counted day would be Tuesday.
I was using this logic however it is not what I need
1 + 5 * (_days_between (cast([Finish] as date);cast([Start] as date))
-_day_of_week (cast([Finish] as date);1)+_day_of_week (cast([Start] as date);1))/7
if (_day_of_week (cast([Start] as date);1) > 5) then (6) else (_day_of_week (cast([Start] as date);1))
if (_day_of_week (cast([Finish] as date);1) > 5) then (5) else (_day_of_week (cast([Finish] as date);1))
If the database column with the dates is continuous, meaning it is not missing any date records you could try:
total(if ((_day_of_week ([Introduction date],1<>7 ) and( [Introduction date] between _add_days(?startDate?,1) and ?EndDate?))
then
(1)
else
(0))
Related
I am trying to create a saved search that shows total orders today, yesterday, this week and this month. I am able to get all but the weekly one using date formulas.
All are Formula(Numberic) fields with summary type Count.
Today: CASE WHEN {trandate} = to_date({today}) THEN {number} END
Yesterday: CASE WHEN {trandate} = to_date(({today} - 1)) THEN {number} END
This Week??
This Month: CASE WHEN {trandate} BETWEEN to_date(TRUNC({today}, 'MONTH'), 'MM/DD/YYYY') AND to_date(LAST_DAY{today}) THEN {number} ELSE 0 END
Any suggestions appreciated!
The way to get this depends on whether you want values for the last 7 days or for this calendar week.
For the last 7 days:
case when {now} - {trandate} < 7 then {number} else 0 end
or for the current week
case when to_char({now}, 'IW') = to_char({trandate}, 'IW') then {number} else 0 end
where 'IW' is for the ISO Standard week numbering. You can also use 'WW' for week numbering where week 1 starts on Jan 1, week 2 on Jan 8 etc.
I'd suggest calculating the day of the week and using that to work back to the start of the week.
I have not tested, but my understanding is that Oracle db functions should work.
to_date({today} - to_char({trandate}, 'D'))
https://livesql.oracle.com/apex/livesql/file/content_GCEY1DN2CN5HZCUQFHVUYQD3G.html
I want to create a rolling list of dates in Excel like so:
Day Date
Day 1 01-Jul-19
Day 1 02-Jul-19
Day 1 03-Jul-19
Day 1 04-Jul-19
Day 1 05-Jul-19
Day 1 06-Jul-19
Day 1 07-Jul-19
Day 2 02-Jul-19
Day 2 03-Jul-19
Day 2 04-Jul-19
Day 2 05-Jul-19
Day 2 06-Jul-19
Day 2 07-Jul-19
Day 2 08-Jul-19
Day 3 03-Jul-19
Day 3 04-Jul-19
Day 3 05-Jul-19
Day 3 06-Jul-19
Day 3 07-Jul-19
Day 3 08-Jul-19
Day 3 09-Jul-19
Day 4 04-Jul-19
. .
. .
. .
So essentially what's happening is that the 7-day range moves forward by one day each time, from a specific start date (in the example above, 01-07-19) until it reaches an end date. Is there an automated way of doing this?
#ashvin10 you can do this in vba, but you can also accomplish this with 2 formulas without using vba at all, here's how:
for illustration purposes we'll just assume you are starting with 07/01/2019 on the first row and your information will be displayed in columns A and B.
in A1 enter the string Day 1
in B1 enter your starting date, like 07/01/2019
in A2 enter this formula: ="Day " & IF(MOD(ROW(A2),7)<>0, MID(A2,5,(LEN(A2)-4)), MID(A2,5,(LEN(A2)-4))+1)
in B2 enter this formula: =IF(A2=A1,B1+1,OFFSET(B2,-7,0)+1)
highlight cells A2 and B2
click on the cross that becomes available on the bottom right hand corner of cell B2
drag down the formula till you hit the end date you desire
the cells are populated with the values you requested in the format you requested
If you absolutely have to have it done using vba please let me know and I can show you how to do it that way as well, but this way is much easier.
EDIT: #ashvin10 I'm so sorry, the original formula I instructed you to put into A2 only works for Day 1 through Day 9, if you go into days past 9 it won't display correctly. I've fixed the formula that should be pasted into A2 so now it will work no matter how many days you go down. I'm so sorry for the confusion.
Alternatively, this can also be done in Python.
import datetime
start_date = '01-07-2019'
end_date = '31-01-2020'
output_file_name = 'rolling dates'
output_file_extension = '.CSV'
delimiter = '\t'
with open((output_file_name + output_file_extension.lower()), 'w+') as file:
header = "Day" + delimiter + "Date" + '\n'
file.write(header)
start_date_object = datetime.datetime.strptime(start_date, '%d-%m-%Y').date()
end_date_object = datetime.datetime.strptime(end_date, '%d-%m-%Y').date()
number_of_days = abs((end_date_object - start_date_object).days)
next_day = start_date_object
for i in range(1, number_of_days + 2):
for j in range(7):
file.write(("Day {0}" + delimiter + next_day.strftime('%d-%m-%Y') + '\n').format(i))
next_day += datetime.timedelta(days=1)
start_date_object += datetime.timedelta(days=1)
next_day = start_date_object
After running the code above, I simply created a blank Excel file and then imported the data from the CSV file output by this code.
This is arguably more complicated than #gharbad-the-weak's answer but thought I'd include this anyway.
I need a formula to:
recognize the quarter for each date
divide the revenue in half for the start and end quarter.
Below is an example of the results I'm looking for. Need this to be a formula I can build in SmartSheet and/or Excel and transfer over to a SmartSheet.
Add a "helper row" with quarter number and year so you can use a SUMIFS/2
=(SUMIFS($[Est Revenue]#row, $[Start Date]#row, IFERROR((ROUNDUP(MONTH(#cell) / 3) + "" + YEAR(#cell)), 0) = [Q1 2020]$1) + SUMIFS($[Est Revenue]#row, $[End Date]#row, IFERROR((ROUNDUP(MONTH(#cell) / 3) + "" + YEAR(#cell)), 0) = [Q1 2020]$1)) / 2
The helper row would be quarter number before the 4 digit year. So 12020 would be quarter 1 2020.
Im trying to create a calculator for detention of containers.
Each provider has different rules that have a breakdown between work days and calendar days.
for example:
the first 5 working days (excl Saturday and Sunday) are free of cost
After that the next 3 calendar days are at a cost of 135
After the above, the next 5 calendar days are at a cost of 160
After that 180 onward.
is this possible to do in excel? My idea is to have a difference between 2 dates: date of arrival versus date of return. and based on the 4 rules below use "IF" to give me a cost.
what would be a more efficient way to do this?
HardCoded option:
With Dynamic array formula SEQUENCE()
=SUM(IF(SEQUENCE(B1-A1+1,,A1)<WORKDAY(A1,5),0,IF(SEQUENCE(B1-A1+1,,A1)<WORKDAY(A1,5)+3,135,IF(SEQUENCE(B1-A1+1,,A1)<WORKDAY(A1,5)+8,160,180))))
Older version:
=SUM(IF(ROW(INDEX($ZZ:$ZZ,A1):INDEX($ZZ:$ZZ,B1))<WORKDAY(A1,5),0,IF(ROW(INDEX($ZZ:$ZZ,A1):INDEX($ZZ:$ZZ,B1))<WORKDAY(A1,5)+3,135,IF(ROW(INDEX($ZZ:$ZZ,A1):INDEX($ZZ:$ZZ,B1))<WORKDAY(A1,5)+8,160,180))))
As an array formula, using Ctrl-Shift-Enter to confirm instead of Enter when exiting edit mode.
Using a lookup table.
Put 0 in the first cell in the lookup table. The second cell would get the formula =WORKDAY(A1,5) the next below: =F2+3 and the last =F3+5 and put the corresponding values:
Then use SUMPRODUCT and LOOKUP:
=SUMPRODUCT(LOOKUP(SEQUENCE(B1-A1+1,,A1),F1:F4,G1:G4))
older version:
=SUMPRODUCT(LOOKUP(ROW(INDEX($ZZ:$ZZ,A1):INDEX($ZZ:$ZZ,B1)),F1:F4,G1:G4))
Below is a VBA function that accepts three arguments - the start date, the end date, and the name of the carrier, and returns a cost. Only costing for one carrier is included, but it can be expanded for other carriers.
Function fContainerCost(dtmStart As Date, dtmEnd As Date, strCarrier As String) As Currency
Dim lngDays As Long
Select Case strCarrier
Case "CarrierA"
dtmStart = WorksheetFunction.WorkDay(dtmStart, 5)
If dtmStart > dtmEnd Then
fContainerCost = 0
Else
lngDays = DateDiff("d", dtmStart, dtmEnd) + 1 ' need to get the actual days, so get the difference in dates and add 1.
If lngDays <= 3 Then
fContainerCost = fContainerCost + (135 * lngDays)
Else
fContainerCost = fContainerCost + (135 * 3)
lngDays = lngDays - 3
If lngDays <= 5 Then
fContainerCost = fContainerCost + (160 * lngDays)
Else
fContainerCost = fContainerCost + (160 * 5)
lngDays = lngDays - 5
fContainerCost = fContainerCost + (180 * lngDays)
End If
End If
End If
Case "CarrierB"
End Select
End Function
To use it, just treat it as a regular Excel function:
=fContainerCost(A1,B1,C1)
Regards,
In Google Spreadsheet, or excel if its the same, how do I find the last weekday of day D only if D is not a weekday itself.
I.E:
If D equals weekday = do nothing (D equals D).
If D equals weekend = D equals last weekday.
Edit: i tried this to get the workday one month away:
WORKDAY(EDATE(N18, 1)+1, -1)
But I Was getting some weird results. Perhaps it counts red days as well, but I never specified the region anywhere.
Edit again:
This above example actually works, eg:
=WORKDAY("2013-04-06"+1, -1)
=WORKDAY("2013-04-06"+1, -1)
...does the trick.
Another option may be:
=IF(WEEKDAY(D1, 2) > 5, D1 - (WEEKDAY(D1, 2) - 5), D1)
It's not so straightforward, but you can use something like that:
=IF(OR(WEEKDAY(A1)=1,WEEKDAY(A1)=7),A1-CHOOSE(WEEKDAY(A1),2,,,,,,1),A1)
Basically, if the weekday is 1 or 7 (Sunday or Saturday, as this is how Excel treats weekdays), return the date minus 2 if Sunday or minus 1 if Saturday, else the date itself.