Trouble with an MDX query

44 Views Asked by At

I have this query that works perfectly well, however if I add another dimension in the rows it affects the result for some Equipments. The purpose of the query is if the equipment doesn't have any Count, then it should retrieve the count of the last equipment inside the source Segment Equipment that the equipment belongs to. This is the query that works perfectly:

WITH MEMBER [Measures].[test] AS
           IIF
   (
        NOT ISEMPTY([Measures].[Count]) ,
        ([Measures].[Count]),
        
            TAIL(
            (EXISTING ([Dim Equipment Attribute].[Source Segment Equipment Id].[Source Segment Equipment Id].Members)
            ,FILTER(
                [Equipment Name].[Equipment Name].Members ,
                [Measures].[Count]>0))
            ,1).Item(0)                         
    )
SELECT
{[Measures].[test]} ON COLUMNS,
([Dim Equipment Attribute].[Equipment Name].[Equipment Name].Members) ON ROWS
FROM [DB DWH]

Here's the query with the added dimension on rows :

    WITH MEMBER [Measures].[test] AS
           IIF
   (
        NOT ISEMPTY([Measures].[Count]) ,
        ([Measures].[Count]),
        
            TAIL(
            (EXISTING ([Dim Equipment Attribute].[Source Segment Equipment Id].[Source Segment Equipment Id].Members)
            ,FILTER(
                [Equipment Name].[Equipment Name].Members ,
                [Measures].[Count]>0))
            ,1).Item(0)                         
    )
SELECT
{[Measures].[test]} ON COLUMNS,
([Dim Equipment Attribute].[Equipment Name].[Equipment 
Name].Members, [Dim Equipment Attribute].[Equipment Angle]. 
[Equipment Angle].Members) ON ROWS
FROM [DB DWH]

I assume that the EXISTING is causing the issue, however I dont know what else to use. This is my first MDX query that I worked on

I tried to change the EXISTING, however by doing so the result in the first query are also invalid

1

There are 1 best solutions below

0
Subbu On

Typically the SELECT query of MDX is as follows: Assuming you mostly likely want a cross-join The normal bracket "(" and curly bracket "{" means different things in MDX!

SELECT
{
   [Measures].[test]
} ON COLUMNS,
{ 
    [Dim Equipment Attribute].[Equipment Name].[Equipment Name].Members
    * [Dim Equipment Attribute].[Equipment Angle].[Equipment Angle].Members
} ON ROWS
FROM [DB DWH]

i.e., within curly braces, you would list all your dimensional fields AND also use the "*" operator, to denote cross-join.