Cognos Report Studio - For loop? - report

I have a COGNOS package for data on processes within my company. They all have a start date, and unfinished processes have no end date. A process is active on date x if the start date is before x, and the end date is after x, or is empty. The package doesn't have a time series.
The company needs a report with the number of active processes at the end of each month, for the past two years. With no time series to iterate, I had to be creative. I created 24 data items, each with the formula below:
IF (([Start Date] <= _last_of_month(_add_months(current_date;-1))) and
(([End Date] is missing) or
([End Date] > _last_of_month(_add_months(current_date;-1)))))
THEN (1) ELSE (0)
... subtracting 1 to 24 months. Then, I added each on a column on the report's crosstable.
Well, this solution is really ugly, and unmaintanable. Is there a way to iterate a variable on Report Studio, creating a line or column for each iteration?
Thanks!

You can simulate time series in Report Studio.
There are some options:
If you are allowed to SQL in RS. Create a Query Subject like:
select _last_of_month(_add_months(current_date;-1)) as Month
union all
select _last_of_month(_add_months(current_date;-2)) as Month
union all
....
Create a query subject from existing table with dates. Query item [Month]
_last_of_month([date_field])
Filter it by
[date_field] < _add_months(current_date;-24)
and check query property "Auto Group and Summarize" is set "Yes".
Be careful an choose small but dense table as a source.
Create Query subject based on any existing table with more than 24 rows. Add a Query Item with expression
1
Call it "1" as well. Add another QI, call it [Back], expression
running-total([1])
Filter it:
[Back] <= 24
Add another QI with expression
_last_of_month(_add_months(current_date;-[Back]))
This is your [Month] field
Than join this Query Subject with your process list by condition
[Time series].[Month] > [Process].[Start Date] and
([Time series].[Month] < [Process].[End Date] or [End Date] is missing)
Than just count rows for every [Month]

Related

Apache Drill: Group by week

I tried to group my daily data by week (given a reference date) to generate a smaller panel data set.
I used postgres before and there it was quite easy:
CREATE TABLE videos_weekly AS SELECT channel_id,
CEIL(DATE_PART('day', observation_date - '2016-02-10')/7) AS week
FROM videos GROUP BY channel_id, week;
But it seems like it is not possible to subtract a timestamp with a date string in Drill. I found the AGE function, which returns an interval between two dates, but how to convert this into an integer (number of days or weeks)?
DATE_SUB may help you here. Following is an example:
SELECT extract(day from date_sub('2016-11-13', cast('2015-01-01' as timestamp)))/7 FROM (VALUES(1));
This will return number of weeks between 2015-01-01 and 2016-11-13.
Click here for documentation

How do you update an existing date to a random date in a range?

In one of my tables I have datetime field in which the data in the table column is populated with something like "2016-01-07 01:33:00".
What I want to do is change ONLY the date to a random date within a range (ie: 2016-02-01 thru 2016-02-28) without changing the time. The end result might be "2016-02-13 01:33:00".
What mysql command string would accomplish this task?
Something like
UPDATE someTable SET someDate = DATE_ADD(
someDate,
INTERVAL
DATEDIFF(rangeStart, someDate) +
ROUND(RAND()*DATEDIFF(rangeEnd, rangeStart))
DAY
);
where someTable.someDate is your existing data, and rangeStart and rangeEnd are the boundaries of your target date range.
Here you take the initial date, add enough days to it to reach the range start, and then further add a random number of days no greater than the number of days in your target range.
In MsSQL it could be:
select dateadd(day,cast((RAND() * 30) as int),getdate())
Substitute getdate() with your input date.
(RAND() * 30) is used to randomly generate a number of days up to 30.

Get RowCount With Date Comparasion in SSRS

I am new to SSRS.
I have a dataset, my dataset brings data from a stored procedure.
one of the parameters of my sp is StartDate and another one is EndDate. Their type is datetime
And the table has a dateTime Column called Date.
I have two gauges and I wanna bind integer values to my gauges.
First one is the count of rows where Date < DateAdd(DateInterval.Hour,24,StartDate)
and te second is count of rows where Date > DateAdd(DateInterval.Hour,24,StartDate)
How will I write the exact script. Whatever I wrote is not working.
I appreciate any help, thanks.
You need to set the gauge Pointer value as something like:
=Sum(IIf(DateDiff(DateInterval.Day, Parameters!StartDate.Value, Fields!Date.Value) >= 1
, 1
, 0))
This is counting rows where the time difference is less than a day compared to the parameter StartDate. Just change it slightly to get those where the difference is at least a day:
=Sum(IIf(DateDiff(DateInterval.Day, Parameters!StartDate.Value, Fields!Date.Value) >= 1
, 0
, 1))
Worked fine for me in a quick test:

Error in repeating table sum in InfoPath

I'm using InfoPath 2003 to produce a form which includes a repeating table of records that include a date field (StartDate) and a value field (TotalElapsed). I have date pickers for start and end dates on the form (beginDate and endDate), and there is a text box after the table which I want to have show the total sum of the integer field for records that have a date between the start and end date selections. The text box value parameter generated when I use the 'Insert Field or Group...' and 'Filter Data...' options, is below:
sum(#TotalElapsed[msxsl:string-compare(#StartDate, beginDate) >= 0 and msxsl:string-compare(#StartDate, endDate) <= 0])
This gives almost the correct sum calculation, with the exception that any records with a date that matches the end date are not included in the sum. Any records with dates from (and including) the start date, up to the day before the end date, are all included in the sum. Any ideas why the end date records aren't included in the sum?
Thanks
The above equation works fine. To use the >= and <= the Start Date should be in type of Date.
sum(Total[msxsl:string-compare(StartDate, BeginDate) >= 0 and msxsl:string-compare(StartDate, EndDate) <= 0])

how to get a average of days with two different tables

There are two tables 1)HR_OrderRequest (column to be considered is HRdate) other columns are HRUID,UID
2)HR_Supplydetails(colmn to be considered is HRUID) other columns are createddttm,UID
by considering the date from HR_Supplydetails we should find the average days taken for that particular UID time taken to release of HRdate .I have a problem getting a average of days
Please do the need .
You can do a datediff:
SELECT AVG(DATEDIFF(day, createddttm,HRdate))
And then do your join on the two tables.
so the steps would be first getting the number of days for a order so you have like these tables:
order (id, date) # this date is the date the order was placed
supply (id, date) # this date is the date the order was filled
these might not be right but i think they are close
select avg(days)
from (select (supply.date-order.date) as days
from order join supply on order.id=supply.id)
but the sub query isn't needed as it can be written as:
select avg(supply.date-order.date)
from order join supply on order.id=supply.id;
now to map this to your tables:
HR_OrderRequest (HRUID, UID, HRdate)
HR_Supplydetails (HRUID, UID, createddttm)
select avg(HR_OrderRequest.HRdate-HR_Supplydetails.createddttm)
from HR_OrderRequest join HR_Supplydetails on HR_OrderRequest.HRUID=HR_Supplydetails.HRUID
where UID=?
clearly if you have date functions use them

Resources