5
votes

I'm havin hard time to understand how to filter out result of multidimensional expression.

This is my database schema.

A simple database schema

And this is my data.

Manufacturer
╔════╦═══════════════════╗
║ Id ║       Name        ║
╠════╬═══════════════════╣
║  1 ║ Awesome Computers ║
║  2 ║ TailSpin Toys     ║
╚════╩═══════════════════╝

Item
╔════╦═════════╦════════════════╦═══════╗
║ Id ║  Name   ║ ManufacturerId ║ Stock ║
╠════╬═════════╬════════════════╬═══════╣
║  1 ║ PC      ║              1 ║    40 ║
║  2 ║ Server  ║              1 ║    10 ║
║  3 ║ STB     ║              2 ║    80 ║
║  4 ║ Console ║              2 ║    50 ║
╚════╩═════════╩════════════════╩═══════╝

Part
╔════╦══════════════════╦════════╦══════════╦═══════╗
║ Id ║       Name       ║ ItemId ║ StatusId ║ Stock ║
╠════╬══════════════════╬════════╬══════════╬═══════╣
║  1 ║ MBO              ║      1 ║        1 ║   100 ║
║  2 ║ Processor        ║      1 ║        1 ║   100 ║
║  3 ║ Server MBO       ║      2 ║        2 ║    20 ║
║  4 ║ Server processor ║      2 ║        2 ║    20 ║
║  5 ║ Main box         ║      3 ║        2 ║    40 ║
║  7 ║ Adapter          ║      3 ║        3 ║    30 ║
║  8 ║ Controller       ║      4 ║        2 ║    40 ║
║ 10 ║ Adapter          ║      4 ║        1 ║    60 ║
║ 11 ║ Memory card      ║      4 ║        2 ║    80 ║
╚════╩══════════════════╩════════╩══════════╩═══════╝

Status
╔════╦═════════════╗
║ Id ║    Name     ║
╠════╬═════════════╣
║  1 ║ No data     ║
║  2 ║ Available   ║
║  3 ║ Unavailable ║
╚════╩═════════════╝

I imported everything into the tabular model solution. After this, I created two measures:

  • Table Item: ItemStock:=SUM([Stock])
  • Table Part: PartStock:=SUM([Stock])

Then I deployed the cube to the server.

By running the following MDX query...

SELECT 
    NON EMPTY { 
        [Part].[Name].CHILDREN
    } ON ROWS,
    { 
        [Measures].[PartStock]
    } ON COLUMNS
FROM [Model]
WHERE (
    {
        [Status].[Id].&[1]
    }
)

...I get this resultset...

╔═══════════╦═══════════╗
║           ║ PartStock ║
╠═══════════╬═══════════╣
║ Adapter   ║        60 ║
║ MBO       ║       100 ║
║ Processor ║       100 ║
╚═══════════╩═══════════╝

...which is ok.

However, when running this MDX query...

SELECT 
    NON EMPTY { 
        [Item].[Name].CHILDREN
    } ON ROWS,
    { 
        [Measures].[ItemStock]
    } ON COLUMNS
FROM [Model]
WHERE (
    {
        [Status].[Id].&[1]
    }
)

...I'm getting this resultset...

╔═════════╦═══════════╗
║         ║ ItemStock ║
╠═════════╬═══════════╣
║ Console ║        50 ║
║ PC      ║        40 ║
║ Server  ║        10 ║
║ STB     ║        80 ║
╚═════════╩═══════════╝

I was expecting that items in the ItemStock table would be filtered out by Part table as a many-to-many relationship. E.g. MBO, Processor and Adapter have references to items 1 and 4, so the result would be constrained to them, and the result should turn out like this:

╔═════════╦═══════════╗
║         ║ ItemStock ║
╠═════════╬═══════════╣
║ Console ║        50 ║
║ PC      ║        40 ║
╚═════════╩═══════════╝

What am I doing wrong?

1
Answered on the question you posted to DBA: dba.stackexchange.com/questions/119909/…GregGalloway

1 Answers

0
votes

MDX is unknown for me but here is a pure SQL explanation.

Your model is actually like this:

Link to image

To get [Items] for [Parts] with spesific [Status] I would to use this pure SQL:

SELECT Item.Name
FROM Item INNER JOIN Part ON Item.Id = Part.ItemID
WHERE Part.StatusID = 1;

I can see in your sample that you use FROM [Model], but you have no table named Model in your setup - so this might be a VIEW or some functionality for MDX you should look into. It could be that the JOIN between tables are wrong for the [Model] view.