简体   繁体   English

MDX基于IF且大于

[英]MDX Calculated measure based on IF and greater than

I am editing my question which I want exactly. 我正在编辑我想要的问题。

I have two columns Actual Units , Future Units from Fact A and Fact B respectively but at same granular level.I also have Demand Units from Fact B 我有两列实际单位 ,分别是事实A和事实B的未来单位 ,但粒度相同。我也有事实B的需求单位

My requirement is : 我的要求是:

1. Projected Units = Coalesce(Actual Units,Future Units)    
2. Stock Units = IF(Projected Units > Demand Units,Demand Units,Projected 
Units)
3. Stock Rate = (Stock Units/Demand Units)    

在此处输入图片说明

I cannot join the two facts in the data source view level and do the 我无法在数据源视图级别加入这两个事实,并且
calculation there because they are a very huge tables, so I think the performance would be very slow. 因为那里有一个非常大的表,所以我认为性能会很慢。 If you say that doing the calculations at the data source view level level is the only way we have, please let me know. 如果您说在数据源视图级别进行计算是我们唯一的方法,请告诉我。

Did you get this? 你明白了吗?

When calculating the grand total MDX is summing up A, summing up B, and then comparing them. 在计算总计MDX时,要对A求和,对B求和,然后对它们进行比较。

If you want the calculation to occur at the row level (checking whether B>A) then edit the Data Source View and add a new calculated column to the table your measure group is based upon. 如果您希望计算在行级别进行(检查B> A),则编辑“数据源视图”,并将新的计算列添加到度量值组所基于的表中。 The calculated column should be: 计算列应为:

CASE WHEN B>A THEN A ELSE B END

Then create a Sum measure based upon that new column. 然后根据该新列创建求和度量。

This approach will perform much better compared to any completely MDX approach to calculating this at a very detailed grain. 与以非常详细的粒度进行计算的任何完全MDX方法相比,该方法的性能要好得多。 If your fact tables had 500,000 rows or less and you had a degenerate Dimension which was the same grain as the grain you need to calculate at, we could possibly do it in MDX. 如果事实表的行数为500,000或更少,并且退化的Dimension与需要计算的粒度相同,则可以在MDX中进行操作。 But since you are concerned with SQL query performance I am assuming the tables are big. 但是由于您担心SQL查询的性能,所以我假设表很大。 Just remember that SQL is done once at processing time. 只要记住,SQL在处理时就执行一次。 MDX is calculated in every query at query time. MDX是在查询时间在每个查询中计算的。 So do expensive things in SQL when you can. 因此,您可以使用SQL进行昂贵的工作。

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

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