简体   繁体   中英

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

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.

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. 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. 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. But since you are concerned with SQL query performance I am assuming the tables are big. Just remember that SQL is done once at processing time. MDX is calculated in every query at query time. So do expensive things in SQL when you can.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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