Archer GRC: Calculate number days between two date fields - archer

When my values list Respondent Status changes to “Completed” I need to Calculate the number days between Date Initiated (date field) and Respondent Status Date Change (date field).
IF([Respondent Status ] = VALUEOF("Completed"),
DATEDIF([Date Initiated ], [Respondent Status Date Change], DAY),
How do I account for it the value isn't Completed? Something with true or false statements?

You can reference the field itself (and it will retain the current value) or a static value.
IF([Respondent Status] = VALUEOF([Respondent Status],"Completed"),
DATEDIF([Date Initiated], [Respondent Status Date Change], DAY),
[FIELD])
IF([Respondent Status] = VALUEOF([Respondent Status],"Completed"),
DATEDIF([Date Initiated], [Respondent Status Date Change], DAY),
0)

Related

Select subscription date range

How to turn a date into last month's date?
SELECT extract(day from (Select (period_start) from accounts where id = 'id')) AS "Day of month";
The above give me the day of the month
Account Table
id (primary)
startPeriod
User records
timestamp
account_id (foreign key)
The user is registered at 02-12for subscription start
I would like to have a query to select the date range from the current month to last month
This current month is April, so I would like to select the record that is
select records from table where date > '03-12-2022'
get the subscription start period and get the date
set the query limited to last month with the subscription start date
how to produce this date 03-12-2022 which is driven by subscription start period and previous month?
many thanks
This approach should work:
Get the number of months between the subscription date and today e.g. age(timestamp1, timestamp2)
Get the number of months and subtract 1 to get last month e.g. duration = extract(month from age(timestamp1, timestamp2)) - 1
Add the months to the subscription date e.g. (subscription_date + (duration || ' month')::INTERVAL)

Query to show only unique records based on certain criteria in ACCESS

I am working on a database that is something like this.
enter image description here
In the event a job number when both current week and previous week in the "sort" column happens, choose only the current week row.
enter image description here
The first or last function don't work here as the current week or previous week record can either be the first or last row of a particular job number.
You can group on the job and select the max date:
Select [Job Number], Max([Order Date]), YourWeekFunction(Max([Order Date]))
From YourTable
Group By [Job Number]

BigQuery using MAX() function

So I have a query in BQ that looks as such:
SELECT
SubscriptionId,
start_time,
STRFTIME_UTC_USEC((UTC_USEC_TO_MONTH(TIMESTAMP_TO_USEC(TIMESTAMP(start_time)))),'%B %Y') AS cohort_month,
UTC_USEC_TO_MONTH(start_time) AS usec_month,
STRFTIME_UTC_USEC((UTC_USEC_TO_WEEK(TIMESTAMP_TO_USEC(TIMESTAMP(start_time)), 0)),'%Y-%m-%d') AS cohort_week,
WEEK(start_time) AS usec_week,
DATE(start_time) AS cohort_day,
UTC_USEC_TO_DAY(start_time) AS usec_day,
amount,
current_period_start,
current_period_end,
cancel_date,
end_date,
cancel_at_period_end,
salesRepEmail,
CASE WHEN (salesRepEmail IS NOT NULL) THEN 'Telesales' ELSE 'Online' END AS sales_channel,
status,
type_id,
CASE WHEN (type_id IN ('150032',
'150033',
'150023')) THEN 'Annual' ELSE 'Monthly' END AS duration,
refunded
FROM
[data_snapshots_daily.subs_charges_refunds_]
WHERE
start_time >= '2016-04-01 00:00:00'
AND refunded = FALSE
What I'm looking to do though, is add on to the query so that it returns all the relevant data from the most recent month, week, and day.
So I imagine it involves something to do with MAX(usec_month) but I can't figure it out. Remember, I only want it to return relevant data when it's included in the most recent month (June)
i think of something like below
for current month
WHERE YEAR(CURRENT_DATE()) = YEAR(start_time)
AND MONTH(CURRENT_DATE()) = MONTH(start_time)
for current week
WHERE YEAR(CURRENT_DATE()) = YEAR(start_time)
AND WEEK(CURRENT_DATE()) = WEEK(start_time)
for current day
WHERE CURRENT_DATE() = DATE(start_time)
quick add
for last two weeks play with something like below (should be improved to handle first week of the year)
WHERE (YEAR(CURRENT_DATE()) = YEAR(start_time) AND WEEK(CURRENT_DATE()) = WEEK(start_time))
OR CASE WHEN WEEK(CURRENT_DATE()) = 1
THEN (YEAR(CURRENT_DATE()) - 1 = YEAR(start_time) AND 53 = WEEK(start_time))
ELSE (YEAR(CURRENT_DATE()) = YEAR(start_time) AND WEEK(CURRENT_DATE()) - 1 = WEEK(start_time))
END
Breakdown of above statement (per your request)
It looks for starttime that either belong to current or previous week. Current week is straightforward. In case of previous week it looks if current week is not the first week of the year - in this case condition is - same year but previous week. And in case if current week is first week of the year - it looks for last week of previous year.
cleaner version to handle last two weeks condition
DATE(start_time)>DATE(DATE_ADD(CURRENT_DATE(),-7*1-DAYOFWEEK(CURRENT_DATE()),'DAY'))
changing 1 in 7*1 to let's say 3 - will give you condition for last four weeks for example

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

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.

Is it possible to create a dynamically calculated field?

How can I create a dynamically calculated field to determine the age in days based on a date/time stamp?
For example say I have a field that has a date time stamp. What I want to be able to see when browsing the cube is a column showing the number of days since the time stamp. So if the date time stamp is '8/21/13 12:00PM' and I browse the cube on '8/22/13 12:00PM', the calculated column "Number of Days Since" would show 1.
Is this even possible with SSAS?
Yes, you can:
with member Measures.[date string] as
Left(Right([Date].[Date].CurrentMember.UniqueName, 9), 8)
member Measures.[date formatted] as
Left(Measures.[date string], 4) + "-" +
Mid(Measures.[date string], 5, 2) + "-" +
Right(Measures.[date string], 2)
member Measures.[date date] as
CDate( Measures.[date formatted])
member Measures.[to today] as
now() - Measures.[date date]
, format_string = 'yy" years, "m" months, "d" days"'
select {
Measures.[date string],
Measures.[date formatted],
Measures.[date date],
Measures.[to today]
}
on columns,
[Date].[Date].[Date].Members
on rows
from [Adventure Works]
gives what you want. You do of course not need all the intermediate measures, they just show step by step what is calculated.
One remark, however: I formatted the to today measure with a date format using yy. A four digit year would show as "1912 years" etc, as SSAS is internally using the date coding like Excel of number of days since Jan, 1, 1900. I mis-used the date formatting here to format a duration, which is a number and not a real date. This formatting approach is only giving correct results for positive durations less than 100 years. But this is only a formatting issue and the main duration calculation is correct nevertheless. It just shows the duration in days, and the time within the day as fractions.