0% found this document useful (0 votes)
47 views3 pages

Cognos RS - Functions - 19

This document provides examples of SQL code to retrieve the current period in different databases and formats. It also provides formulas for calculating other relative time periods like quarters, year-to-date, trailing twelve months, and month-over-month percentage change.

Uploaded by

Harry Konnect
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views3 pages

Cognos RS - Functions - 19

This document provides examples of SQL code to retrieve the current period in different databases and formats. It also provides formulas for calculating other relative time periods like quarters, year-to-date, trailing twelve months, and month-over-month percentage change.

Uploaded by

Harry Konnect
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

For Microsoft SQLServer the calculation should look like this:

cast_integer(convert({varchar},[Returned items (query)].[Time dimension].[Date],112))

For Oracle:

to_number(To_Char([Returned items (query)].[Time dimension].[Date], 'YYYYMMDD'))

Useful links

Cognos Time and Date Functions from temple university

Find Current Period using closingPeriod Function

closingPeriod ([sales_and_marketing_cs].[Time].[Time].[Month])

Find Current Period by Filtering on Measure Data

item(tail(filter(members([sales_and_marketing].[Time].[Time].[Month]), tuple([Revenue],
currentMember([sales_and_marketing].[Time].[Time])) is not null), 1), 0)

Check link for detail explanation


http://www.ibm.com/developerworks/data/library/cognos/reporting/dimensional_queries/page561.html

Current Month/Quarter/YTD/ Trailing Twelve Months

Often use a “base” month current period to build everything else off of:
[Month Current] = closingPeriod( [goc].[Years].[Years].[Month] )

Quarter
parent( [Month Current] )

YTD
total( currentMeasure within set
periodsToDate( [goc].[Years].[Years].[Year], [Month Current] ) )

Trailing Twelve Months


total( currentMeasure within set
lastPeriods( 12, [Month Current] ) )

Month % Change Prior Year


( [Month Current] - [Month Prior Year] ) / [Month Prior Year]
Where [Month Prior Year] = lag( [Month Current] , 12 )

Note: currentMeasure is in the context of the crosstab


Period to date

[monthClosingPeriod] =
closingPeriod( [GOC].[Years].[Years].[Month] )

[periodsToDateForClosingPeriodMonth] =
PeriodsToDate( [GOC].[Years].[Years].[Year] , [monthClosingPeriod] )

Show real date from power cube

Cast date to string, want MM/DD/YYYY formatting (Read 3728


times)

Re: Cast date to string, want MM/DD/YYYY formatting

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.

You might also like