We've got the following script:

WITH 
SET [Last56Days] as
 TAIL ( [Date].[Date - Calendar Month].[Calendar Day].members, 56 )
MEMBER [Measures].[DateValue] as
 [Date].[Date - Calendar Month].CURRENTMEMBER.member_value, format_string = "short date"
MEMBER [Measures].[DateValue2] as
 [Date].[Date - Calendar Month].CURRENTMEMBER.member_value, format_string = "dd/mm/yyyy"
SELECT
    { [Measures].[DateValue], [Measures].[DateValue2]} ON COLUMNS,
    Hierarchize ({ [Last56Days] } ) ON ROWS
FROM [Our Cube]

It returns this:

enter image description here

Can I change the date format somehow so that the dates are like this "09 Feb 2014" i.e. shorter ?

有帮助吗?

解决方案

From the comments I suppose that the issue is that you have integer date keys and a name column which is always of type string in Analysis Services. These will not work with date formats which need dates (or doubles containing the days since January, 1, 1900, and as fractions the time of day, i. e. 8:30 am would be 8.5/24).

Thus, you could use

MEMBER [Measures].[Date as int] as
       [Date].[Date - Calendar Month].CURRENTMEMBER.Properties('Key0', Typed)
MEMBER [Measures].[Date Year] as
       Fix([Measures].[Date as int] / 10000)
MEMBER [Measures].[Date Month] as
       Fix(([Measures].[Date as int] - [Measures].[Date Year] * 10000) / 100)
MEMBER [Measures].[Date Day] as
       [Measures].[Date as int] - [Measures].[Date Year] * 10000 - [Measures].[Date Month] * 100
MEMBER [Measures].[DateValue] as
       // convert it to Date data type and use a format string on that:
       DateSerial([Measures].[Date Year], [Measures].[Date Month], [Measures].[Date Day]),
       format_string = 'dd/mm/yyyy'

See the documentation of Properties and the list of VBA functions like Fix and DateSerial.

Looking at the complexity of my above code, it may be better to use string logic instead of integer logic, i. e. omitting the typed argument to Properties and then calculating year, month, and day using Left, Mid, and Right and converting that to integers. But "the details of that are left as an exercise to the reader".

其他提示

Try with one of this format:

 =Format(Fields!myDateTime.Value, "M/d/yy") ... 6/15/09 
 =Format(Fields!myDateTime.Value, "M/d/yyyy h:mmtt") ... 6/15/2009 2:45PM 
 =Format(Fields!myDateTime.Value, "MM/dd/yy HH:mm") ... 06/15/09 14:45 
 =Format(Fields!myDateTime.Value, "MMM d, yyyy") ... Jun 15, 2009 
 =Format(Fields!myDateTime.Value, "Short Date") ... 6/15/2009 
 =Format(Fields!myDateTime.Value, "Long Date") ... Monday, June 15, 2009 
 =Format(Fields!myDateTime.Value, "ddd dd/MM/yyyy") ... Mon 04/04/2011 

Source Link. Hope it helps

EDIT I'm sorry! I didn't see the comment in the end. Anyway, I guess you've already seen this Link but you perhaps can try to use the format_string like so:

format_string = "dd/mmm/yyyy"
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top