计算 MDX 中的累积和
我需要一个 MDX 查询,它根据度量的累积和返回前 N% 的行。棘手的部分是,必须根据与用于求和的度量不同的度量对集合进行排序,因此无法使用 TopPercent
函数。
为了澄清我需要什么,这是一个例子。我想以尽可能少的包装购买至少 1000 克肉。然而,这不仅仅是包装的重量,我想要的是质量,所以我想优先考虑肉类含量最高的产品。可用的产品如下:
|| Name || Weight || PercentageOfMeat ||
| Product 1 | 500 | 20 |
| Product 2 | 250 | 60 |
| Product 3 | 1000 | 25 |
| Product 4 | 400 | 50 |
| Product 5 | 400 | 40 |
因此,为了获得我想要的产品,我首先按 PercentageOfMeat 降序排序以满足我的首要任务。然后我会将产品的重量累加起来,直到达到 1000 克的限制。结果应该是产品 2、产品 4 和产品 5。这很简单。
但在 MDX 中可以做到这一点吗? TopPercent
(或者在本例中为TopSum
)本来是完美的,但它不允许我使用不同的度量进行排序和求和。如果我只想要最重的产品,那就行了。引用文档,该函数:
按降序对集合进行排序,并返回累积总计等于或大于指定百分比的最高值的元组集合。
我基本上需要的是 TopPercent
函数,它不会对集合进行排序,但据我所知,没有。那么是否可以做我想做的事情,或者我必须在服务器代码中计算它?
I need a MDX query which returns the top N percent of the rows based on a cumulative sum of a measure. The tricky part is that the set must be ordered based on a different measure than is used for the sum, so using the TopPercent
function is not possible.
To clarify what I need, here's an example. I want to buy at least 1000 grams of meat in as few packages as possible. However, it is not just about the weight of the package, I want quality, so I want prioritize products that contain the highest percentage of meat. The available products are these:
|| Name || Weight || PercentageOfMeat ||
| Product 1 | 500 | 20 |
| Product 2 | 250 | 60 |
| Product 3 | 1000 | 25 |
| Product 4 | 400 | 50 |
| Product 5 | 400 | 40 |
So, to get what I want, I would first sort descendingly by PercentageOfMeat to meet my first priority. Then I would sum the weights of the products cumulatively until I reach the 1000 gram limit. The result should be Product 2, Product 4 and Product 5. That's simple enough.
But is it possible to do this in MDX? TopPercent
(or in the case of the example, TopSum
) would otherwise be perfect, but it does not allow me to use different measures for sorting and summing. If I wanted just the products that weight the most, it would work. To quote the documentation, the function:
Sorts a set in descending order, and returns a set of tuples with the highest values whose cumulative total is equal to or greater than a specified percentage.
What I basically need is TopPercent
function that does not sort the set, but as far as I know, there is none. So is it possible to do what I want or do I have to calculate this in server code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先结合 Order() 来根据肉类百分比对产品进行排序,然后根据累积重量对其进行 Filter() 怎么样?
在[Adventure Works]中,以下代码显示了订购最多且累计销量低于某个值的山地自行车:
给出以下内容:
How about combining an Order() first to get your products sorted according to their percentage of meat and then Filter() them according to their cumulative weight ?
In [Adventure Works] the following code is showing the most ordered mountain bikes whose cumulative sales amount is lower to a certain value:
giving the following: