Anda di halaman 1dari 7

Hi all

I have a my date as ' yyyymm' in the model query item(database ). e.g entrydate.

My filter is like this.


[entrydate] >= ?P_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

Create a query calculation new_Date as


cast(extract(year,?Parameter1?),char(4))+cast(extract(month,?Parameter1?),char(2))

then disabled the filter on your date and add this


Your Date column=New_date

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

create Year ->cast(extract(year,?Parameter1?),char(4))

create Month as->


If(extract(month,?Parameter1?) >10) then
(cast(extract(month,?Parameter1?),char(4)))
else
('0'+cast(extract(month,?Parameter1?),char(4)))

then create New_Date as [Year]+[Date]

then apply the same filter


Your Date column=New_date
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.

case when (?Parameter AND-OR?)='AND'

then ((1 in_range ?P_ENTRDATE? OR [entrydate ]in_range ?P_ENTRDATE?) AND

(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

then enable Ur 'AND/OR' filter.

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).

case when (?Parameter AND-OR?)='AND'

then ((1 in_range ?P_ENTRDATE? OR [entrydate ]in_range ?P_ENTRDATE?) AND

(1 in_range ?P_TRANSACTION_DATE? OR
[transdate] 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
[transdate] in_range ?P_TRANSACTION_DATE?))

end

---------------------------

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

Oracle date functions


Get the last day of the week select trunc(sysdate, 'DAY')+6 from dual;

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

SQL server date functions

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)

Useful Query items

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)

#/* QTD */#


if ([Fact Table].[Dim Time].[Quarter Id] = [Fact Table].[Dim Time].[Fact Current Year]*10+[Fact
Table].[Dim Time].[Fact Current Quarter Number])
then ([Fact Table].[Fact Table].[Measure])
else (0)
#/* HTD */#
If ( [Fact Table].[Dim Time].[Fact Current Quarter Number] > 2 ) Then
( If ( [Fact Table].[Dim Time].[Quarter Number] > 2) Then
( If ([Fact Table].[Dim Time].[Quarter Id] <= [Fact Table].[Dim Time].[Fact Current Year]*10+[Fact
Table].[Dim Time].[Fact Current Quarter Number])
Then [Fact Table].[Fact Table].[Measure])
else (0) )
Else ( 0) )
Else (
If ([Fact Table].[Dim Time].[Quarter Id]<=[Fact Table].[Dim Time].[Fact Current Year]*10+[Fact
Table].[Dim Time].[Fact Current Quarter Number])
then ([Fact Table].[Fact Table].[Measure])
else (0) )

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'))#
)

Identifying nth Weekday of a month in reports


Requirement: Identify the 2nd Thursday of the current month. Solution: Create data items ToDate,
1stDateofMonth, 1stDayofMonth, Nth, Day , AddDays, NthDay ToDate - current_date 1stDateofMonth -
_first_of_month(ToDate) 1stDayofMonth - _day_of_week(1stDateofMonth ,1) // Assuming Monday is Day 1
Nth - 2 // The nth value of the weekday required, in our case we require 2nd Thursday Day - 4 // Assuming
Monday is Day 1, then Thursday is Day 4 AddDays - case when [Day] >= [1stDayofMonth] then [Day] -
[1stDayofMonth] else ([Day] + [1stDayofMonth]) -1 end NthDay - _add_days([1stDateofMonth],(([Nth]-1) * 7
) + [AddDay]) NthDay returns the 2nd Thursday of the month.

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...

Create a query Calculation as below...


_years_between (current_date, [Birth date column])

Calculate Age in yy years, mm months and dd days format...

(replace [Birth Date] with your own Data of birth column)

substring (cast(_ymdint_between (current_date, [Birth date]),char(6)),1,2) || ' Years '||

substring (cast(_ymdint_between (current_date, [Birth date]),char(6)),3,2)

|| ' months ' ||

substring (cast(_ymdint_between (current_date, [Birth date]),char(6)),5,2)

|| ' Days '

http://cognosskills.blogspot.in/

=============

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.

Anda mungkin juga menyukai