2015-10-19 33 views
1

我正在使用Microsoft商业智能开发工作室2012试图创建一个计算字段,该字段将给我一个名为'createdon'的字段的Month和Week编号。如何格式化日期以包含周数?

我是SQL新手,经过一番研究,我已经拿到了代码。

=Format(Fields!createdon.Value, "MMMM") & " Week " & (Int(DateDiff("d",DateSerial(Year(Fields!createdon.Value),Month(Fields!createdon.Value),1), Fields!FullDateAlternateKey.Value)/7)+1).ToString 

但我得到的错误:

"The Field expression for the dataset 'Dataset1' refers to the field 'FullDateAlternateKey'. Report item expressions can only refer to fields within the current datasetscop or, if inside an aggregate, the specified dataset scope. Letters in the names of fields my use the correct case.

我知道这意味着“FullDateAlternateKey”不是一个有效的字段名,但我不知道该替代哪些字段名称,而不是纠正这种表达。有更多经验的人有什么想法可以解决这个问题吗?

理想情况下,我希望它的格式设置为显示“以星期为结尾”的列。 于是从2015年9月26日至2015年10月2日的任何日期会说:“周的2015年10月2日”

+0

为什么不使用日期部分( “W”,Createdon.value)返回星期? – MiguelH

回答

0

试试这个:

="Month: " & Datepart("m", Fields!createdon.Value) & " Week: " & 
Datepart(DateInterval.WeekOfYear,Fields!createdon.Value) 

您将获得以下:Month: 10 Week: 43

编辑您的问题并添加所需结果的示例,以帮助您使用特定格式。

更新:

试试这个:

="Today: " & Format(Fields!createdon.Value,"dd/M/yyyy") & "Week Of: " & Format(
DATEADD("d" ,7-DATEPART(DateInterval.WeekDay,Fields!createdon.Value,FirstDayOfWeek.Monday),Fields!createdon.Value), 
"dd/M/yyyy") 

它会显示:Today: 19/10/2015 Week Of: 25/10/2015

+0

好吧!已更新以提供更多细节。 –

+0

@ Shawn.parker检查我的更新。 –

+0

干杯队友!这工作完美 –