date - mdx query to calculate difference between measure at nearest quarter date and measure today
问题描述
I am trying to calculate a measure which is the difference between a measure (say, profit) today and the nearest preceding quarter.
E.g.: if the quarter months are March, June, September and December, then:
If the current month is May, then the calculated
measure = Profit(May)-Profit(March)
If the current month is November, then the calculated
measure = Profit(November)-Profit(September)
If the current month is December, then the calculated
measure = Profit(December)-Profit(September)
I'm new to MDX and would really like some help on this.
I'm aware of .CurrentMember.PrevMember to get the previous member, but that doesn't help if you don't know how many previous members calls you should use.
解决方案
欢迎来到 MDX。要解决这个问题,您需要对“User Hierarchy”有基本的了解。另外,您应该了解“currentmember”、“parent”、“lag()”和“lastchild”的功能。
基于此,请遵循以下示例。我正在尝试在 2013 年重新制作您在 AdventureWorks 上的示例。
让我们先看看2013年的所有互联网销售额
select
{[Measures].[Internet Sales Amount]}
on columns,
{
[Date].[Month of Year].[Month of Year]
}
on rows from
[adventure works]
where
[Date].[Calendar Year].&[2013]
结果
现在让我们做一个测量,得出上一季度最后一个月的值
with
member [Measures].[LastMonthOfPreviousQuater] as
([Date].[Calendar].currentmember.parent.lag(1).lastchild,
[Measures].[Internet Sales Amount])
select
{[Measures].[Internet Sales Amount],[Measures].[LastMonthOfPreviousQuater]}
on columns,
{
[Date].[Calendar].[Month].&[2013]&[09]
}
on rows from
[adventure works]
推荐阅读
- c# - 如何在 ASP.NET MVC 中将一个表中的 ID 保存到另一个表中?
- html - 如何将多个输入字段的预选值映射到角度6的数组中
- python - 哪个协程是顺序的?
- python - 如何使用其他库编译 kivy 项目?
- swift - 如何根据 Swift 中的数据抛出和处理错误?
- c# - 使用 PerRequestLifetimeManager() 配置的 Unity 为 WebApi 请求的每个请求创建多个 DbContext 实例,但不是 MVC 请求
- minitab - 本地 Minitab 宏中的计算和打印无法正常工作。怎么修?
- reactjs - 如果我的基本路由相同,histroy.push() 在反应路由器中不起作用
- php - 在方法中调用 javascript 函数
- swift - 列表涵盖 SwiftUI 中的自定义视图