问题
This is a follow up question to this previous question
I have the following working code:
WITH
SET NewIDs AS
INTERSECT(NonEmpty([ID].Children, CROSSJOIN([Date].&[T-1], [Category].&[Old]))
, NonEmpty([ID].Children, CROSSJOIN([Date].&[T], [Category].&[EOD]))
)
SELECT
NON EMPTY([Dim2].Children
) ON 0
,
NON EMPTY([NewIDs]
) ON 1
FROM [MyCube]
WHERE [Measures].[Value]
However I would like to have another dimension on rows, not the ID (let's call it Dim1)
I have tried the below, but it does not work (as I don't think you can slice on named sets)
WITH
SET NewIDs AS
INTERSECT(NonEmpty([ID].Children, CROSSJOIN([Date].&[T-1], [Category].&[Old]))
, NonEmpty([ID].Children, CROSSJOIN([Date].&[T], [Category].&[EOD]))
)
SELECT
NON EMPTY([Dim2].Children
) ON 0
,
NON EMPTY([Dim1].Children
) ON 1
FROM [MyCube]
WHERE [Measures].[Value]
, [NewIDs]
EDIT: Some further clarity. I usually aggregate the Value measure, and look at it in a table of Dim2 on columns and Dim1 on rows (this will include all IDs). However now I want to just have this but sliced only on the [NewIDs] set.
EDIT2: Using the below code almost solves my question, but on rows I have an unwanted column where every value is NewIDs ideally which I would like not to have.
WITH
SET NewIDs AS
INTERSECT(NonEmpty([ID].Children, CROSSJOIN([Date].&[T-1], [Category].&[Old]))
, NonEmpty([ID].Children, CROSSJOIN([Date].&[T], [Category].&[EOD]))
)
MEMBER [ID].[NewIDs] AS
Aggregate([NewIDs])
SELECT
NON EMPTY([Dim2].Children
) ON 0
,
NON EMPTY([ID].[NewIDs] * [Dim1].Children
) ON 1
FROM [MyCube]
WHERE [Measures].[Value]
回答1:
Do you get an error if you aggregate before adding to the WHERE clause?
WITH
SET [NewIDs] AS
INTERSECT(
NonEmpty(
[ID].Children,
([Date].&[T-1], [Category].&[Old])
)
, NonEmpty(
[ID].Children,
([Date].&[T], [Category].&[EOD])
)
)
MEMBER [ID].[All].NewIDs AS
AGGREGATE( [NewIDs] )
SELECT
NON EMPTY([Dim2].Children
) ON 0
,
NON EMPTY([Dim1].Children
) ON 1
FROM [MyCube]
WHERE
( [Measures].[Value]
, [ID].[All].NewIDs );
Try chucking the whole expression into the WHERE clause:
SELECT
NON EMPTY([Dim2].Children) ON 0
,NON EMPTY([Dim1].Children) ON 1
FROM [MyCube]
WHERE
( [Measures].[Value]
, AGGREGATE(
INTERSECT(
NonEmpty(
[ID].Children,
([Date].&[T-1], [Category].&[Old])
)
, NonEmpty(
[ID].Children,
([Date].&[T], [Category].&[EOD])
)
)
)
);
来源:https://stackoverflow.com/questions/49980765/slicing-over-a-named-set