Professional Documents
Culture Documents
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:
to_number(To_Char([Returned items (query)].[Time dimension].[Date], 'YYYYMMDD'))
Useful links
Quarter
parent( [Month Current] )
YTD
total( currentMeasure within set
periodsToDate( [goc].[Years].[Years].[Year], [Month Current] ) )
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
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.