Cognos RS - Functions - 13
Cognos RS - Functions - 13
'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 )
When it is requested to get Half to date, get reference date first as data item, then get date started. CYTD-
Current year to date; PYTD- Prior year to date; CHTD-Current half year to date; PHTD-Prior half year to date
[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] ) )
[periodsToDateForClosingPeriodMonth] =
PeriodsToDate( [GOC].[Years].[Years].[Year] , [monthClosingPeriod] )
Current Day_Date
descendants ([Current Day],1)
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)
Age calculation
We have two ways to calculate age in years and age in yy years mm months and dd days format
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"
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.