current date minus one month crystal report - date

How to calculate current date(month) minus one month in crystal report?

To subtract one month from the current date use
DateAdd ("m", -1, CurrentDate)
If you just want the month number use this
Month(DateAdd ("m", -1, CurrentDate))
If you are trying to get the month name use this
MonthName(Month(DateAdd ("m", -1, CurrentDate)))

Related

Countif date includes year, month or day

I have a column containing dates in a Google sheet. How can I count the number of dates that include a specific year, month or day?
I have tried the following: =COUNTIF(G:G, YEAR(2000)) which just returns a zero, although there are multiple dates in the year 2000 in that column.
All the best!
year:
=INDEX(COUNTIF(YEAR(G:G), 2000))
month:
=INDEX(COUNTIF(MONTH(G:G), 11))
=INDEX(COUNTIFS(MONTH(G:G), 12, G:G, "<>"))
day:
=INDEX(COUNTIF(DAY(G:G), 27))
weekday:
=INDEX(COUNTIF(WEEKDAY(G:G, 1), 7))

SharePoint custom list date and time validation

I have a custom list that I'm trying to restrict data entry for valid day of week and time.
My current column validation works for day of week being Monday, Wednesday or Friday. It looks like this:
=CHOOSE(WEEKDAY([Requested date for approval]),FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE)
I'm trying to figure out the syntax to add that it also has to be between 8 am and 12:00 pm on those days.
Any help would be greatly appreciated.
You would use an AND statement to include a second criteria
=AND(CHOOSE(WEEKDAY([Requested date for approval]),FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE),
AND(
[Requested date for approval]-INT([Requested date for approval])*24 >= 8,
[Requested date for approval]-INT([Requested date for approval])*24 <= 24
)
)
I confess, I've never heard of the CHOOSE function, but the time calculation is based on the information at Microsoft
Convert times
To convert hours from the standard time format to a decimal number, use the INT
function.
Column1 Formula Description (possible result)
10:35 AM =([Column1]-INT([Column1]))*24 Number of hours since 12:00 AM (10.583333)
12:15 PM =([Column1]-INT([Column1]))*24 Number of hours since 12:00 AM (12.25)
EDIT
To calculate the day of the week, you can use the TEXT function to return the day of the week (i.e. Monday)
=TEXT(WEEKDAY([ColumnName]), "dddd")
It won't be pretty, but you can use a series of AND logical operators
=AND(
TEXT(WEEKDAY([Requested date for approval]), "dddd") = "Monday",
AND(
TEXT(WEEKDAY([Requested date for approval]), "dddd") = "Wednesday",
AND(
TEXT(WEEKDAY([Requested date for approval]), "dddd") = "Friday",
AND(
[Requested date for approval]-INT([Requested date for approval])*24 >= 8,
[Requested date for approval]-INT([Requested date for approval])*24 <= 24
)
)
)
)
Posting Working Solution
=IF(
AND(
CHOOSE(
WEEKDAY([Requested date for approval]),FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE
),
([Requested date for approval]-INT([Requested date for approval]))*24>=8,
([Requested date for approval]-INT([Requested date for approval]))*24<=12
),
TRUE
)

SSRS expression, iif statement with date conditions

So my default values for startDate and endDate in SSRS were set up with the following ssrs expressions.
first day of previous month ssrs expression
=DateAdd(DateInterval.Month, -1, DateSerial(Year(Date.Now), Month(Date.Now), 1))
last day of previous month ssrs expression
=DateAdd(DateInterval.Day, -1, DateSerial(Year(Date.Now), Month(Date.Now), 1))
But that won't work alone in my case unless I want to go in on the 16th of every month and generate this report for the people requesting it for the first 15 days of the current month.
So in my default value expression for start date i am trying this iif statement...
= iif(
DatePart(DateInterval.Day, Today() <> "20",
DateInterval.Month, -1, DateSerial(Year(Date.Now), Month(Date.Now), 1),
DateInterval.Month, 1, DateSerial(Year(Date.Now), Month(Date.Now), 1)
)
Not working out so well. So what i'm trying to do is.....
Change the default start and end date based on what day of the current month it is, So if current day of the current month equals 16, make start date 1 of current month and end date 15 of current month, if current day of the month isn’t 16 make start date first of previous month and end date last day of previous month. So then the only thing needed is to get subscription emails and what day to send them out on.
Untested, but what if you try this? (for your start date parameter):
= iif(
DatePart(DateInterval.Day, Today()) <> "16",
DateAdd(DateInterval.Month, -1, DateSerial(Year(Date.Now), Month(Date.Now), 1)),
DateSerial(Year(Date.Now), Month(Date.Now), 1)
)

Previous month in parameter

I need to set a Hidden Default Parameter in SSRS.
In my query I need to not show last months total but the month before that, ie in Feb I need to show Dec totals.
I usually use this for last month but cannot tweak it for the month prior.
Set first date of last month:
=DateAdd("m", -1, DateSerial(Year(Now()), Month(Now()), 1))
Set last date of last month:
=DateAdd("d", -1, DateSerial(Year(Now()), Month(Now()), 1))
If i understand you right you want to:
Get the first day of two months from now
=DateAdd("m", -2, DateSerial(Year(Now()), Month(Now()), 1))
And you want to get the last day on month two months from now
=DateAdd("d" , -1 , DateAdd("m", -1, DateSerial(Year(Now()), Month(Now()), 1)))
Depending on exactly what you need, use something like:
DateAdd
(
DateInterval.Month
, -1
, DateAdd(DateInterval.Day, -1, DateSerial(Year(Parameters!Date.Value), Month(Parameters!Date.Value), 1))
)
Used in a report:

Crystal Report exclude time entries based on holiday rules

Working on report to determine an employees utilization (utilization is defined as number of billable versus non billable hours in a given report period).
The issue is I need to exclude holidays from my equation. While much has been written on identifying holidays, i need some additional help.
I do not have access to the backend MS. SQL database in order to create a holiday table, so I need to filter dates in the report.
Holidays I need to exclude are
New Year's Day (January 1)
Memorial Day (last Monday in May)
Independence Day (July 4)
Labor Day (first Monday in September)
Thanksgiving (fourth Thursday in November)
1/2 Day Christmas Eve (December 24)
Christmas (December 25)
1/2 Day New Year's Eve (December 31)
Here are the rules I need to follow:
A recognized holiday that falls on a Saturday will be observed on the preceding Friday.
A recognized holiday that falls on a Sunday will be observed on the following Monday.
currently I have the report working by calculating total available minutes (each workday = 480 minutes) so for normal holidays I need to remove them from total hours worked, and from the total hours available). For the half day holidays I need to remove 240 minutes from total available and to discard any minutes worked above 240).
I hope that makes sense.
Create a custom-function named 'Observance' with the following text:
//Correct date to match business rules
Function (Datevar value)
Select DayOfWeek(value)
//Sunday; add a day
Case 1: Date(DateAdd("d", 1, value))
//Saturday
Case 7: Date(DateAdd("d", -1, value))
//no change
Default: value
;
Create a custom-function named 'FullHolidays' with the following text:
//create a list of full-day holidays, calculated dynamically
Function (Numbervar yyyy)
Datevar Array holidays;
Datevar holiday;
//New Year's day
holiday:=Date(yyyy, 1, 1);
Redim Preserve holidays[Ubound(holidays)+1];
holidays[Ubound(holidays)]:=Observance(holiday);
//Memorial Day (last Monday in May)
//TODO
//Independence day
holiday:=Date(yyyy, 7, 4);
Redim Preserve holidays[Ubound(holidays)+1];
holidays[Ubound(holidays)]:=Observance(holiday);
//Labor Day (first Monday in September)
//TODO
//Thanksgiving (fourth Thursday in November)
//TODO
//xmas day
holiday:=Date(yyyy, 12, 25);
Redim Preserve holidays[Ubound(holidays)+1];
holidays[Ubound(holidays)]:=Observance(holiday);
holidays;
Create a custom-function named 'HalfHolidays' with the following text:
//create a list of half-day holidays, calculated dynamically
Function (Numbervar yyyy)
Datevar Array holidays;
Datevar holiday;
//xmas eve
holiday:=Date(yyyy, 12, 24);
Redim Preserve holidays[Ubound(holidays)+1];
holidays[Ubound(holidays)]:=Observance(holiday);
//new year's eve
holiday:=Date(yyyy, 12, 31);
Redim Preserve holidays[Ubound(holidays)+1];
holidays[Ubound(holidays)]:=Observance(holiday);
holidays;
Use in a formula like:
If {Table.DateField} IN FullHolidays(Year({Table.DateField})) Then
0
Else If {Table.DateField} IN HalfHolidays(Year({Table.DateField})) Then
240
Else
480
I'll leave the Thanksgiving (and other such holidays) calculation in your capable hands (I'm too busy watching House).