Archer GRC: Formula based on setting current date between specific time frames - archer

I have a date field which I need to use a formula in Archer.
I need to set the current date on the field which I have called DateField when a user selects a value field, ValueField, and changes to the values "Pre-Approved" or "Approved" or "Updated" if it is before 7AM, if it is after 7AM it would show the next date.
Here's what I have so far:
IF(AND(ISEMPTY([DateField]),
"",
IF(AND(NOT(ISEMPTY([DateField])), [???]=VALUEOF([???],"False")),
DATEADD(DAY, 1, [ValueField]),
))

From what I understand, what you want is:
ALGORITHM:
If ([ValueField] is changed to 'Pre-Approved', 'Approved' or 'Updated') AND (current time is before 7AM)
then
set [DateField] to current date
Else If ([ValueField] is changed to 'Pre-Approved', 'Approved' or 'Updated') AND (current time is after 7AM)
then
set [DateField] to (current date+1)
Make sure this formula is in the [DateField] field.
FORMULA:
IF(
AND(HOUR(NOW())<7,OR([ValueField]=VALUEOF([ValueField],"Pre-Approved"),[ValueField]=VALUEOF([ValueField],"Rejected"),[ValueField]=VALUEOF([ValueField],"Updated"))),
NOW(),
IF(
AND(HOUR(NOW())>7,OR([ValueField]=VALUEOF([ValueField],"Pre-Approved"),[ValueField]=VALUEOF([ValueField],"Rejected"),[ValueField]=VALUEOF([ValueField],"Updated"))),
DATEFORMAT(DATEADD(DAY, 1, NOW()),"M/d/yyyy")
)
)
You can add your other validations to the beginning of the first IF statement.
And thanks for making the Archer community grow on stackoverflow.

Related

Crystal Report adding a year or month based on IF condition

I am trying to add a year to currentdate in Crystal Reports after a if condition (if a user renews a month it will add a month, a year it will add a year to current date), but it's not working. I created a date field type and in formula editor I put the below formula I tried the below
If {tblcustomers_1.Customertypeofpay}="yearly" then DateAdd("yyyy", 1, CurrentDate)) else
DateAdd("mm", 1, CurrentDate))
I tried so many ways for date add and still not working please help.
Change it to:
If {tblcustomers_1.Customertypeofpay}="yearly" then
DateAdd("yyyy", 1, CurrentDate) else DateAdd("m", 1, CurrentDate)
You had extra ')' and extra 'm'.
Most likely, your typeofpay field is numeric rather than text.

Continue increment on Date field using DayOfYear?

I am looking to continue an increment from a date field and start the day of year from this particular date field.
For example (SQL SEVER):
(DATEPART(DAYOFYEAR, CUSTOM_Date) -58) -- Decremented 58 Days to start
I am expecting then 'Jan 01' to continue numbering but instead it goes negative?
You're getting exactly what it is supposed to do. Jan 1 is the first day of a year. That means that the dayofyear for that date will be 1. If you subtract 59(or 58 in your case) from that number you'll get -57.
If you want it to keep incrementing, you'll need to have a start date and use DATEDIFF instead.
Use a variable with the true start date (I called it #startdate) and do the following:
(DATEDIFF(DAY, #startdate, CUSTOM_date) -59)
NOTE: I think in your screenshot you actually did -58, and not -59.

Changing the date used within a query which has been provided by a parameter

I am trying to create a query which will be used within a reporting dashboard. the query needs to pull a date from a parameter which is feed from a datetime control within the dash board.
The issue i have is that the date time control will show the current date or can be changed using a drop down calender. I need the query to look at the date provided and perform a bit of an if statement.
If the date provided is the same month as the current month. I need the date used within the query to be the last day of the previous month. ELSE it should use the last day of the month selected.
I have tried several variations writing my code into the Where Clause but have so far not come to any success. Even just trying to get the query to give me the last day of the previous month (Code below) has not worked.
Any ideas would be welcome. I am really stuck on this.
SELECT A.ETLKEY, A.EFFECTIVEDATE, A.ACTUAL,
FROM DBO.View
WHERE (A.EFFECTIVEDATE = (DateAdd("d", -1, CDate(
"01/"+CStr(Format(&EndDate(),"MM/yyyy"))))))
Second attempt
DECLARE #dtDate DATE
SET #dtDate = &Enddate
--'Month/day/year'
SELECT Case
When #dtDate = '08/01/2016'
-- Last day of previous month, as this month will have no date in it
Then DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,#dtDate),0))
-- Last day of month stated.
Else DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,#dtDate)+1,0))
So final working Code for anyone who might find this useful in the futrue
DECLARE #dtDate DATETime
SET #dtDate = &Enddate
--'Month/day/year'
SELECT Case
--compares month from parameter to todays month
When DATEPART(mm,#dtDate) = DATEPART(mm,GETDATE())
-- Last day of previous month, as this month will have no date in it
Then DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,#dtDate),0))
-- Last day of month stated.
Else DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,#dtDate)+1,0))
END

SSRS optional cascading parameter for date

I have a report that I am attempting to setup a subscription for. The subscriber would like the report on the 4th every month for the previous month's end date. e.g ran today would return the data through 10/31.
I would like to create this report so that there is a cascading parameter that would be labeled Use previous month end date to set the end date to the subscription date when flagged on and allow the user to enter a date when flagged off. so that i can use this parameter to create the dynamic subscription but allow anyone else hitting it through the report server to enter their own date.
Is this possible?
You don't need the UsePriorMonth parameter - just default the date range to be the prior month and allow users to change it if they want.
So your DateFrom parameter Default Value expression is:
=DateAdd(DateInterval.Month, -1, DateAdd(DateInterval.Day, 1-Day(Today), Today))
and your DateTo parameter Default Value expression is:
=DateAdd(DateInterval.Day, -1, DateAdd(DateInterval.Day, 1-Day(Today), Today))

Select rows with date range within another date range

I have a table of accounts that has columns for start date and end date. I want the user to supply a start date and end date and all data must be returned where the account was active at any time between the user specified start date and end date.
The catch is that the end date may be null if the account is still currently active.
The account must be selected if it was open at any time between the user specified range which means that even accounts that were opened or closed between the range must be included.
Here is a picture of what I want.
The yellow part is the date range entered by the user. The green parts is what I want selected. The light red part is what I don't want selected. The arrows on the end of G, H and I mean that those accounts don't have an end date. All other ones that don't have an arrow have an end date.
So, this amounts to checking that the account start date is prior to the user supplied end date and the account end date is after the user supplied start date (or is null, in which case we don't even need to check it):
where
account.start_date < #user_end_date and
(account.end_date >= #user_start_date or account.end_date is null)
SELECT
*
FROM
accounts
WHERE
(start_date >= :user_supplied_start AND start_date <= :user_supplied_end)
OR
(end_date >= :user_supplied_end AND end_date <= :user_supplied_start)
OR
(start_date <= :user_supplied_start AND end_date IS NULL)
SELECT *
FROM accounts
WHERE start_date <= #input_end_date
AND (end_date >= #input_start_date OR (end_date IS NULL AND NOW() >= #input_start_date))