Cognos RS - Functions
Cognos RS - Functions
com/questions/31710492/convert-a-column-that-has-a-data-
type-of-integer-into-date-in-cognos-report-stud
Convert a column that has a data type of integer into date in Cognos report studio
I have a column that appear like this and the data type is integer. I get that data from AS400
server that's why it uses integer data type. The date format is represent as YYYYMMDD
In report studio, I created a data item that would convert this integer column to date time. But
it failed.
cast([WCPDOD], date) UDA-SQL-0219 The function "to_date" is being used for local processing
but is not available as a built-in function, or at least one of its parameters is not supported.RSV-
SRV-0042
cast([WCPDOD], YYYY-MM-DD)
cast([WCPDOD], datetime)
cast_timestamp([WCPDOD], datetime)
cast_timestamp([WCPDOD], date)
cast_integer([WCPDOD], date)
Can someone help me with this? My goal is to get this 20150729 into this 07/29/2015 at least
Data Item2
cast([Data Item1],varchar(10))
Next, use substring to extract out the date components and build a date string:
Data Item3
substring([Data Item2],1,4) + '-' + substring([Data Item2],5,2) + '-' + substring([Data Item2
Data Item4
cast([Data Item3],date)
Of course, this can all be done in a single expression but I broke it out here for clarity.
In SQL Server, you can convert the integer field to varchar and then to a date and then use the
date style 101 to achieve your desired format:
DECLARE @datevalue int = '20150729';
It does not work when I apply this in Cognos report studio. Parsing error before or near position: 71 of:
"convert(varchar(10),cast(cast([WCPDOD] AS varchar(10)) as date), 101);
You will need to do this in your data layer (SQL Server I assume) where you are pulling the data in cognos
=============
OK, report studio is wried . . .
Output shows:
Jan 1, 0001 1 1 -1
Question,
If the month is from Jan to Sept, how do I put a zero in the front
For example, Jan 1, 1990 will become 1990-01 (currently showing 1990-1 as above) ?
Thanks.
greatings
very simple, I would like to see a string YYYY-MM based on a [Payment Date] field.
If [Payment Date] has a value of 2010-10-1 and 2010-9-30, I would like to get
cast(extract(year,[Payment Date]),VARCHAR(4))
If use
cast(extract(month,[Payment Date]),VARCHAR(2))
If use
repeat('0',2)
If use
2010-00
The logic goes if I use Repeat to report the '0' as the leading zero for Sept, then the code should be
Date]),VARCHAR(2)))))
I am really puzzled . . .
cast(extract(year,[date]),varchar(4))||'-'||
'0'||cast(extract(month,[date]),varchar(1)) else
cast(extract(month,[date]),varchar(2)) end
)
=========
http://ravimahazan.blogspot.in/2014/11/use-of-cast-function-in-cognos-report.html
In general cast function defines as who transforms one data type of a column to other one as defined in
the function.
In report studio cast function is used to make two query item with different data type compatible with
each other.
There are different scenarios when cast function is used like to convert date column or to create dummy
column in UNION.
While using cast report author needs to keep in mind about the performance of report.
As any casting of query item is part of Cognos SQL rather than Native SQL,which processed at cognos
server end not at database.
In case you have any question please comment ,i will respond to your query.
================
Hi all
I have a my date as ' yyyymm' in the model query item(database ). e.g entrydate.
Obviously it does not work QE-DEF-0387 Invalid format for numeric prompt 'P_ENTRYDATE'.Could you please
advise on how to cast/convert the Date Prompt value from Date to 201010 format and where to use it.
Please help.
Thanks,
Nandini
Hi try this
parameter1 is parameter of Date prompt
only check with the values for the month like its 201105 or 20115 my solution wil work
for 20115.
if its 201105 then u have make some extra efforts as
hi prince as per your solution (then disabled the filter on your date) which filter to disable. i dont have any filter for
date.
No just mean to say if u currently have added any filter on ur date column for filtering then disable it.else u can
skip this step.
Try and let me Know
Hi prince
I have a 'AND/OR' propmt in between the 2 date propmts which have the case statement as shown below.
(1 in_range ?P_TRANSACTION_DATE? OR
[entrydate] in_range ?P_TRANSACTION_DATE?))
else
((1 in_range ?P_ENTRYDATE? OR [entrydate] in_range ?P_BOOKING_ENTRY_MONTH?) OR
(1 in_range ?P_TRANSACTION_DATE? OR
[entrydate] in_range ?P_TRANSACTION_DATE?))
end
when i disable this filter iam not getting errors but mismatch of data. but when i enable it iam getting multilpe
errors.
dont knw wat exactly is the problem. pl guide me
Hi,
Try to cast the new_date column which we derived from date prompt to integer As Cast([Year]+[Date], Integer).
then keep
old filter as [entrydate] >= New_date
Thanks .
Hi prince
i have 2 date prompts, 1 is 'entry date prompt' and other is 'trans date prompt'. my report data depends on And/Or
selection prompt between these two date prompts.
little modification in the below case statement pl have a look and guide me further. there are 2 different data items
on which 2 different respective prompts depends(P_ENTRDATE >> entrydate, ?P_TRANSACTION_DATE? >>
transdate).
else
((1 in_range ?P_ENTRYDATE? OR [entrydate] in_range ?P_BOOKING_ENTRY_MONTH?) OR
(1 in_range ?P_TRANSACTION_DATE? OR
[transdate] in_range ?P_TRANSACTION_DATE?))
end
===================
I have a dropdown value prompt on prompt page which is populated using 'Calendar Date' field from 'Date'
Dimension.
I have also applied filter in query of value prompt query to display dates greater than '31-12-2008' which works
fine.
Till this point everything is functioning as expected but now Users want to see Current Month's last date should be
displayed when they run the report .
You can sort the values in value prompt in desc order and apply one more filter in value prompt query like
calendar_Date<=current_Month.
Now you can add javascript to remove 1 st 2 line and making the 1stvalue as default value..
=======
Hi all
I have a problem where i am getting an error when filtering on a data item. Below is my data item,
so i want ot show in my list report an entered date for adjustments that are greater than 0 basically
else 2000-01-01.
My filter is below this case statement where i want to only show this the below case statement
which is lesser or greater than '2000-01-01'
I have also included my error and i have tried casting using many different casting functions.
My case statement called KMS Maintenance Date
My Filter
My Error
UDA-EE-0094 The operation "less_equal" is invalid for the following combination of data types:
"varchar" and "date2"
Thanks in Advance
Sounds like the "[DATE]" in your "and [DATE] <=current_date" part of the case statement needs to
be cast-ed to a date so that its data type matches what's being returned by "current_date".... or vice
versa I s'pose.
==================
Date Manipulation
I'm new to cognos and cant figure out how to do something that should be quite simple. I want to get the first day
of the month from a date from my stored procedure. I have tried cognos syntax, sql syntax, setting the connection
to Limited Local, setting the connection interface to OR instead of OL (saw this on a post and have no idea what it
would even do), and anything else i could find in the past few days. I just want to get the month from the procedure
data for grouping, graphing etc. Below i have some functions i have tried but all come back with the same
error. The function "insertfunctionnamehere" is being used for local processing but is not available as a
built-in function, or at least one of its parameters is not supported
I have tried....
month([fieldname])
_first_of_month([fieldname])
Please help!!! I have googled and searched forums and am completely out of ideas. Thanks.
You want to extract the month? I would just brute force it in Cognos by substring the datetime for the month
numbers, then parse that through a case statement to output January, February, March, etc.
I tried a substring to see if that would make any difference. It did make it a step farther as it tried to run the report
and got to and past the parameters but it failed with An error occurred while performing operation
'sqlOpenResult' status='-28'
So now i dont understand why i am getting this message. And i dont understand what was wrong with all my
previous attempts. Please Help!
Hi Thermos,
Thanks for the reply, but i get the same Local Processing error. The syntax check is fine but
it fails when i try to run it.
to_char is being used for local processing but is not available as a built-in function, or
at least one of its parameters is not supported
I dont believe this is a syntax issue, there must be a setting wrong somewhere. Any other
ideas?
ok, I set the query properties: Processing = Limited Local and Rollup Processing = Local
what should i set things as to be able to use the other available functions in cognos?
you should be able to play with the values of those 2 and get your desired results. Not sure what is going on in your
case. Perhaps, start off with just your date item in your query and work to get the 1st day of month. Once you have
succeeded then proceed to add other items.
I am looking at your orginal post and you mention that you have a stored proc, from which you are trying to extract
the 1st day of month. Have you considered modifying either your SP or FM (Framework Manager) to calculate
what you want and then use it Report Studio?
I think i have enough working that i can fix this one problem, but i Really need to know why i can't do a dateadd,
datepart, etc. I get local processing is not available as a built-in function every time for those.
Kulkarni, thanks for you help and i realize i can do some of this in the procedure but i need a cognos fix. i can't go
back and add fields to SP's every time i need some cosmetic work for a report date header or something like that.
===========
Wednesday, 1 November 2017
Report Studio :Cognos Time and Date Functions
extract(hour,current_timestamp) >>> 10
extract(day,current_timestamp) >>> 13
Extract minute as two digit alpha: case (CAST(extract ( minute, current_timestamp), VARCHAR(2)))
end
ELSE '14'
END
if (extract(month,current_timestamp)♥)
then
timestamp)-1,varchar(4))+'-'+
timestamp),varchar(4))
else
timestamp),varchar(4))+'-'+
timestamp)+1,varchar(4))
)
Dec-Nov
if (extract(month,current_timestamp)<11)
then
timestamp)-1,varchar(4))+'-'+
timestamp),varchar(4))
else
timestamp),varchar(4))+'-'+
timestamp)+1,varchar(4))
_first_of_month(_add_years(current_date;-1))
_last_of_month(_add_months (current_date;-1))
OR
end
or
_last_of_month(date2timestamp(Today()))
or
Between Function:
To filter records based on a timestamp when using date prompts on a prompt page:
(A day is added to the end date to allow for the use of a single day range. That is, the
beginDate will be Apr 27, 2012 12:00:00 AM if April 27 is selected. If April 27 is also
selected as the end date, 24 hours must be added so that the end date used in the filter
This CASE function extracts the first three characters of the current date and translates it
into a fiscal period:
CASE (substr({sysdate},4,3))
WHEN 'JUL' THEN '01'
ELSE '14'
END
To calculate the fiscal year based on the current date (fiscal year for 2009/2010 is 2010):
This function will return the date of the same day of the week a year ago and controls for
leap years. For example, if today is Tuesday, 07/31/2012 then the function returns
08/02/2012 (Tuesday) – trunc removes the time portion of the date value:
trunc(_add_days({sysdate},-364))
TO_CHAR:
Element Description
D Number of day of the week
MI Minute (0-59)
SS Seconds
W Week of month (1-5 where week 1 starts on first day of month and ends
on seventh)
YYYY 4-digit year (YY returns last two digits of 4-digit year)
OTHER
Age in years:
_age([BENEFICIARY_BIRTH_DATE]) / 100
Age in years:
_years_between(current_date,[Date of Birth]) returns number of full years between the two dates
number of full years and fractional months (ex: 21.4) as of the date of graduation
Previous month:
extract(month, _add_months(current_date, -1))
Add/subtract months:
– This will subtract 24 months from the Time stamp month and display the resulting
year.
TRUNC(date, [format])
Quarter Q
Week WW
IW IW
W W
Minute MI
Examples:
Functions Sytax
End of Previous Year trunc({sysdate},'y')-1 When [TIME STAMP] = Aug 3, 2010 5:05:45 PM
Start of day in [TIME STAMP] trunc(_add_days([TIME STAMP], 0),'dd') = Aug 3, 2010 12:00:00 AM
Start of day previous to day in [TIME STAMP] trunc(_add_days([TIME STAMP],-1),'dd') = Aug 2, 2010 12:00:00 AM
Start of the hour in [TIME STAMP] trunc([TIME STAMP], 'hh') = Aug 3, 2010 5:00:00 PM
All records that occurred yesterday [TIME STAMP] between (trunc(_add_days({sysdate}, -1),'dd')) and
(trunc({sysdate}))
If it's Monday, include Decision Dates = Sat, Sun or Mon (((_day_of_week(current_date,1) = 1 ) AND
otherwise DECISION DATE = Current Date:
([Admission Application].[Admissions
Application].[LATEST_DECISION_DATE]
OR
([Admission Application].[Admissions
Application].[LATEST_DECISION_DATE] =
current_date)))
If it’s Monday, then include any record beginning with the start of Friday
through the start
OR
'D'-- Return only day information in the timestamp. Hours, minutes, and seconds are
returned as zero.
'h'-- Return only day and hour information in the timestamp. Minutes and seconds are
returned as zero.
'm'-- Return only day, hour, and minute information in the timestamp. Seconds are
returned as zero.
's'-- Return only day, hour, and second information in the timestamp, but do not show
milliseconds.
TRUNC also can be used with decimal numbers to return a number rounded to a given number
of decimal places.
For example:
_make_timestamp (
cast(#$CurrentDateKey{'Fact TableX'}# /10000 ,integer),
cast(#$CurrentDateKey{'Fact TableX'}# /100, integer) - ( cast(#$CurrentDateKey{'Fact TableX'}# /10000,
integer))*100,
#$CurrentDateKey{'Fact TableX'}# - cast((#$CurrentDateKey{'Fact TableX'}# /100),integer)*100 )
[DateFrom]
case when ([Current Month Number] >6 ) and (?TimePeriodGrp?='CHTD' or ?TimePeriodGrp?='PHTD') then
_make_timestamp (year([DateTo]),07,01)
End
[DateTo]
case
when (?TimePeriodGrp?='PYTD') then ( _add_years ([Dim Time (Activity)].[ Current Date], -1))
End
assume available date is [AvailableDate] and time dimension is [DimTime]: (year(_add_months (_add_days
([Namespace].[DimTime].[ AvailableDate],1),-1)) * 100) + month(_add_months (_add_days ([Namespace].[
DimTime].[ AvailableDate],1),-1))
Get start date and end date based on last available month
string2date (
substring (number2string ([Query1].[Date]),1,4)
+'-'+
substring (number2string ([Query1].[Date]),5,2)
+'-'+
substring (number2string ([Query1].[Date]),7,2)
)
||
right( replace ('0'||cast_char (Month([Returned items (query)].[Time dimension].
[Date]) ,2),' ',''),2)
||
right(replace ('0'||cast_char (day([Returned items (query)].[Time dimension].[Date]) ,
2),' ',''),2))
For Oracle:
Useful links
Quarter
parent( [Month Current] )
YTD
total( currentMeasure within set
periodsToDate( [goc].[Years].[Years].[Year], [Month Current] ) )
Period to date
[monthClosingPeriod] =
closingPeriod( [GOC].[Years].[Years].[Month] )
[periodsToDateForClosingPeriodMonth] =
PeriodsToDate( [GOC].[Years].[Years].[Year] , [monthClosingPeriod] )
Yesterday_Date
descendants ([Yesterday],1)
Useful links
Using the periodsToDate function within IBM Cognos 10 Report Studio to Calculate an OLAP
Running-Total
IBM Cognos 8 Framework Manager - Dimensional Modeling for Time Period Analysis
Get first day of year SELECT TRUNC(TO_DATE('17-DEC-2001'),'YEAR') "First Day" FROM Dual; Get
last Day of Current Month
SELECT add_months(trunc(sysdate) - (to_number(to_char(sysdate,'DD')) - 1), 1) -1 FROM dual
Get the first day of month DATEADD(dd,-(DAY(DT.DAY_DT)-1),DT.DAY_DT) Get date key select
cast(convert(varchar(8), getdate(), 112) as integer) Get last Sunday
Select cast(convert(varchar(8), dateadd(day,-datepart(weekday,dateadd(WEEK,-
1,GETDATE()))+1,dateadd(WEEK,-1,GETDATE())), 112) as integer)
1. Get total reminding to go for product Category XYZ, set 0 if the reminding to go as 0
if (([Product Category] = 'XYZ') and (total ([Forecast] for [Province Id], [Product Category] ) -
total([Sales] for [Province Id], [Product Category]) > 0)) then ( total ([Forecast] for [Province Id],
[Product Category] ) - total([Sales] for [Province Id], [Product Category] )) else (0)
2. TYD, QTD and HTD based day ( Assume [Fact Current Date],[Fact Current Quarter Number] and
[Fact Current Quarter Number] )
#/* YTD at the begining of year*/#
_add_days ([End Date], -_day_of_year ([Fact Table].[Dim Time].[Fact Current Date])+1)
Time filter
filter(
[Time Dimension].[Time Hierarchy].[Date],
roleValue('_businessKey', currentMember([Time Dimension].[Time Hierarchy])) >=
#sq(prompt('From', 'Date'))# and
roleValue('_businessKey', currentMember([Time Dimension].[Time Hierarchy])) <=
#sq(prompt('To', 'Date'))#
)
Age calculation
We have two ways to calculate age in years and age in yy years mm months and dd days format
Calculate Age in years...
http://cognosskills.blogspot.in/
=============
Have a column where the DOB was cast to a varchar. Want to hide certain birthdays so
XX/XX/XXXX shows under certain circumstances. When the cast to varchar was done it formatted
the date as 1994-02-03. I want the date formatted as MM/DD/YYYY. Is there a FORMAT
statement or such that can be done on the dates, or do I perform substrings to move the date
around?
I'd make the same suggestion I did for your other thread and use a conditional style rather than
changing the actual data type of the query item.
Yes, Lynn's suggestion on my other related thread worked like a charm. It was "how to format a
string as currency"
You can't substring a date.
Try these:
select cast(month(getdate()) as varchar(2)) + '/' + cast(day(getdate()) as varchar(2)) + '/' +
cast(year(getdate()) as varchar(4)) -- m/d/yyyy
select right('00' + cast(month(getdate()) as varchar(2)), 2) + '/' + right('00' +
cast(day(getdate()) as varchar(2)), 2) + '/' + right('0000' + cast(year(getdate()) as varchar(4)),
4) -- mm/dd/yyyy
select convert(varchar(10), getdate(), 101) -- mm/dd/yyyy
Replace the getdate() function with whatever your date expression is.