简体   繁体   English

MDX 从 2 年前开始销售到今天

[英]MDX Get Sales starting from 2 years ago to today

I'm trying to make a dynamic report that pull sales starting from the first day of the fiscal year 2 years ago up to today and rolls forward with each new fiscal year.我正在尝试制作一份动态报告,该报告从 2 年前财政年度的第一天开始一直到今天,并随着每个新的财政年度向前推进。 Our fiscal years don't line up with calendar years.我们的财政年度与日历年不一致。 I have little MDX experience and am still learning.我几乎没有 MDX 经验,并且仍在学习。

So it should look at todays date, get the current fiscal year, subtract 2 years from it and then pull sales starting from that year up to today.因此,它应该查看今天的日期,获取当前财政年度,从中减去 2 年,然后从该年开始直到今天的销售额。

I had some difficulty just trying to get the date working correctly as I was getting errors however the below query now pulls yesterdays sales for me.我在尝试使日期正常工作时遇到了一些困难,因为我遇到了错误,但是下面的查询现在为我提取了昨天的销售额。 I assume I need to reference [Date].[Year] as well, but I don't know how to use it to get my desired results.我假设我还需要参考 [Date].[Year],但我不知道如何使用它来获得我想要的结果。

SELECT 
NON EMPTY 
{ [Measures].[Gross Margin Percentage], 
[Measures].[Gross Margin Value], 
[Measures].[Sales Value], 
[Measures].[Sales Units] } 
ON COLUMNS

FROM IMR

Where     
{StrToMember("[Date].[Date].&" + Format(CDate(now()-1), "[yyyy-MM-ddT00:00:00]"))}

If you'd like the results to be across a range of dates then try StrToSet in your WHERE clause and construct in a similar way to what you are doing.如果您希望结果跨越一系列日期,请在WHERE子句中尝试StrToSet ,并以与您正在执行的操作类似的方式构建。

You currently have this:你目前有这个:

Where     
{StrToMember("[Date].[Date].&" + Format(CDate(now()-1), "[yyyy-MM-ddT00:00:00]"))}

Here is an example for 2 days which you can adapt to your needs:这是一个为期 2 天的示例,您可以根据自己的需要进行调整:

Where     
{StrToSet(
   "[Date].[Date].&" + Format(CDate(now()-3), "[yyyy-MM-ddT00:00:00]")
   + ":"
   "[Date].[Date].&" + Format(CDate(now()-1), "[yyyy-MM-ddT00:00:00]")
 )}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM