开发者

Conditional records count with MDX, SQL Server BI

This may be a simple MDX question but I've spent 2 days without any luck.

I have a simple fact table with the following columns:

ID        state        type        price

001        CA          TRUCK       50300
002        MA          BIKE        3010
003        MA          BOAT        0
004        CO          BOAT        20100
...    开发者_开发知识库    ...

I have a cube with 2 dimensions, state and type. Now I'd like to get a count of rows for these two dimensions where price > 0. Can I do it without creating a 3rd dimension (id)? How would I go about doing this? Thanks!


You can first create a new column in your fact table/view -> CountRows which is 1 where the Price is > 0 and NULL otherwise. E.g. (in T-SQL):

...
CASE
    WHEN Price > 0 THEN 1
    ELSE NULL
END CountRows
...

Then, create a new measure with Sum aggregation type on top of this column and you should be good to go. In the example above, this new measure will give you 1 for State.MA and for Type.Boat.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜