根据日期得到 月份

heaven8585 2009-06-22 11:32:06
假设有个层级: [Calendar] : year-month-day

现在我想要根据 日期: [Date].[Calendar].[Date].&[878]
得到他的月份对应的member.

换句话说,不管当前member 是日期还是月份 都返回月份级别上的 成员。

因为我想做一个 caculation, 得到从当月起12月内的销售情况:比如说今天6月 22 日,那我我希望能够得到 从 2008-7 月到 2009年6月的情况, 我只能写出这个,但不准确,因为包含的数据多了。 所以我想得到对应日期的月份,然后月份加1,一直到当前月份。 有什么好的建议么?

WITH MEMBER Measures.[Average Internet Sales Amount] AS

sum(parallelperiod([Date].[Calendar].[Calendar Year],1,[Date].[Calendar].CurrentMember): [Date].[Calendar].CurrentMember,

[Measures].[Internet Sales Amount])

SELECT

{[Measures].[Internet Sales Amount], Measures.[Average Internet Sales Amount]} ON COLUMNS,

NON EMPTY ([Product].[Product Categories].[Category].Members,

[Date].[Calendar].[Date].&[878]
) ON ROWS

FROM [Adventure Works]
...全文
648 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
华芸智森 2009-06-24
  • 打赏
  • 举报
回复
--得到最后一个非空值的月度.
with set [LastMonth] as ' Tail(Filter([Time].[Month].Members, Not IsEmpty([Time].CurrentMember)),1) '
--引用最近的12月
set [Last12Month] as ' [LastMonth].item(0).item(0).Lag(11) : [LastMonth].item(0).item(0)'


select [Last12Month] on COLUMNS,
Non Empty Union(Descendants( [Food], [Product].[Brand Name] ), Descendants( [Drink], [Product].[Brand Name] )) on ROWS
from Sales

7,388

社区成员

发帖
与我相关
我的任务
社区描述
其他数据库开发 数据仓库
社区管理员
  • 数据仓库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧