Equivalent of SQL Not Exists in MDX (or finding another way to accomplish same result)
3
votes
2
answers
1133
views
I am trying to help a contractor implement a cube in Multi-Dimensional SSAS 2017 and do not have very much experience in MDX.
I have a table that looks something like this:
The goal is to only include rows in the query that have the lowest

[seq]
per each combo of [Part]
, [CustomerID]
, and PersonID
after filters have been applied, and then sum the value column. So if no filters are applied, only rows 1 and 3 should be returned and the sum of the value column should be 2. But if the user filters data for only the month of June, only rows 2 and 3 should be returned and the sum of the value column should be 1.
We accomplished this in SQL like this:
SELECT SUM(Value)
FROM (SELECT *
,ROW_NUMBER() OVER (PARTITION BY CustomerID,PersonID, Part ORDER BY SEQ asc) AS Seq
FROM Table WHERE DATEKeY BETWEEN @StartDate AND @EndDate
)A
WHERE Seq=1;
But the contractor is having big problems with performance of the MDX rank function. Not having very much experience with MDX, I am having a hard time knowing what alternatives there are that will perform well and the contractor has not provided any alternatives that match our business need.
Another approach I came up with is this:
SELECT SUM(Value)
FROM [Table] AS A
WHERE DATEKey BETWEEN @StartDate AND @ENDDate
AND CustomerID=@CustomerID
AND NOT EXISTS(SELECT 1 FROM Table AS B
WHERE B.Part=A.Part
AND B.CustomerID=@CustomerID
AND B.PersonID=A.PersonID
AND B.SEQ
Asked by schiznig
(31 rep)
Mar 12, 2018, 08:44 PM
Last activity: Mar 15, 2018, 06:44 AM
Last activity: Mar 15, 2018, 06:44 AM