Filter by a measure value - ssas

Is it possible to filter by a measure value? In my scenario, I need to limit the Widget population by [Measures].[Returned Widget Count] that is a 1 or 0, to only where the Measure = 1. For example something like this:
Select {
(
[Dim Widget].[Build Site].[The Moon],
[Dim Date].[Build Day].[2012-04-24],
[Measures].[Widget Count]
),
(
[Dim Widget].[Build Site].[The Moon],
[Dim Date].[Build Day].[2012-04-24],
[Measures].[Returned Widget Count]
)
} on 0
from (
Select [Dim Widget].[Build Site] on 0
From [Widgetizer]
Where Filter(
[Dim Widget].[Serial Number].Members,
[Measures].[Returned Widget Count].Value > 0
)
)
The query executes, but it is not filtereing my population. I know this because it returns the same result as:
Select {
(
[Dim Widget].[Build Site].[The Moon],
[Dim Date].[Build Day].[2012-04-24],
[Measures].[Widget Count]
),
(
[Dim Widget].[Build Site].[The Moon],
[Dim Date].[Build Day].[2012-04-24],
[Measures].[Returned Widget Count]
)
} on 0
from [Widgetizer]
Where the Filter function has not even been applied.
How can I reduce the population to ONLY where a measure is a specific value?

I think Filter is working properly. The issue might be with the content of the hierarchy (?) [Dim Widget].[Serial Number] - if you have a [All] member than the following filter is going to select it as well :
Filter( [Dim Widget].[Serial Number].Members, [Measures].[Returned Widget Count].Value > 0 )
meaning the sub-select is doing nothing. How about writing :
Filter( [Dim Widget].[Serial Number].Members, [Measures].[Returned Widget Count].Value = 1 )

Related

UNION ALL of 2 MDX queries (within data cube)

I'm mdx rookie..
A box of gold for whoever can tell how to do UNION ALL of these two MDX queries:
SELECT
{
[Measures].[P Count]
}
ON COLUMNS,
{
(
[Dim P View].[Person Key].[Person Key].ALLMEMBERS *
[Dim P View].[Is Sensitive Data A].[Is Sensitive Data A].ALLMEMBERS *
[Dim P View].[Is Sensitive Data B].[Is Sensitive Data B].ALLMEMBERS *
[Dim P View].[Is Person Imp X].[Is Person Imp X].ALLMEMBERS
)
}
DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME
ON ROWS FROM ( SELECT ( { [Dim P View].[Is Person Imp X].&[True] } )
ON COLUMNS FROM [BI_CUBE])
***UNION ALL***
SELECT
{
[Measures].[P Count]
}
ON COLUMNS,
{
(
[Dim P View].[Person Key].[Person Key].ALLMEMBERS *
[Dim P View].[Is Sensitive Data A].[Is Sensitive Data A].ALLMEMBERS *
[Dim P View].[Is Sensitive Data B].[Is Sensitive Data B].ALLMEMBERS *
[Dim P View].[Is Person Imp Y].[Is Person Imp Y].ALLMEMBERS
)
}
DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME
ON ROWS FROM ( SELECT ( { [Dim P View].[Is Person Imp Y].&[True] } )
ON COLUMNS FROM [BI_CUBE])
I tried to append queries via Power Pivot / Power BI - which succeeded but this is main requirement to have it in one query.
Try this:
SELECT
{
[Measures].[P Count]
}
ON COLUMNS,
{
(
[Dim P View].[Person Key].[Person Key].ALLMEMBERS *
[Dim P View].[Is Sensitive Data A].[Is Sensitive Data A].ALLMEMBERS *
[Dim P View].[Is Sensitive Data B].[Is Sensitive Data B].ALLMEMBERS *
{
([Dim P View].[Is Person Imp X].&[True], [Dim P View].[Is Person Imp Y].[All]),
([Dim P View].[Is Person Imp X].[All], [Dim P View].[Is Person Imp Y].&[True])
}
)
}
DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME
ON ROWS FROM [BI_CUBE]

Filter MDX, SQL Server and Analysis Services

I have query like this one:
SELECT NON EMPTY {
[DIM CUSTOMER].[Country Region Code].[Country Region Code].ALLMEMBERS
}
ON COLUMNS,
NON EMPTY CROSSJOIN( {
[DIM PRODUCT].[Category Name].CHILDREN
},
{
[DIM PRODUCT].[Sub Category Name].CHILDREN
})
ON ROWS FROM [Foo]
WHERE (
[Measures].[Order Qty]
);
now I would like to add filtering, basically include only categories and subcategories where at least 10 different products were sold.
I end up with sth like below, but it returns nothing...
SELECT NON EMPTY {
[DIM CUSTOMER].[Country Region Code].[Country Region Code].ALLMEMBERS
}
ON COLUMNS,
FILTER (
CROSSJOIN( {
[DIM PRODUCT].[Category Name].CHILDREN
},
{
[DIM PRODUCT].[Sub Category Name].CHILDREN
},
{ [DIM PRODUCT].[Name].CHILDREN
}),
[DIM PRODUCT].[Name].CHILDREN.COUNT > 0
)
ON ROWS FROM [Foo]
WHERE (
[Measures].[Order Qty]
);
If someone is so proficient that it wouldn't take him 40 minutes to spot mistake like me, please help & thanks in advance :)
Instead of .CHILDREN you may need .members
Maybe swap this:
[DIM PRODUCT].[Name].CHILDREN.COUNT > 0
For this:
[DIM PRODUCT].[Name].CURRENTMEMBER.CHILDREN.COUNT > 0

How to get top 5 in mdx

How to get top 5 from mdx query?
I have a this query:
WITH SET [Geography].[City] AS
TopCount(
[Geography].[City]
,5
,[Measures].[Reseller Freight Cost]
)
SELECT
NON EMPTY {
CROSSJOIN(
{
[Date].[Calendar]
},
{
[Product].[Category]
}
),
CROSSJOIN(
{
[Date].[Calendar].children
},
{
[Product].[Category]
}
)
} DIMENSION PROPERTIES children_cardinality, parent_unique_name ON COLUMNS,
NON EMPTY {
[Geography].[City],
[Geography].[City].children
} DIMENSION PROPERTIES children_cardinality, parent_unique_name ON ROWS
FROM [Adventure Works]
WHERE (
[Measures].[Reseller Freight Cost]
)
But is not working.
Now i have error
error: {"faultstring":"Query (1, 21) Parser: The syntax for '.' is incorrect.","faultcode":"XMLAnalysisError.0xc10e0002"}
The best if I not must change a code after SELECT word .
When you create a set just declare it with no associated hierarchy so this is wrong [Geography].[City].
Also there is a much more readable syntax for cross-join - just use an asterisk *
Try this:
WITH SET [CitySet] AS
TopCount(
[Geography].[City]
,5
,[Measures].[Reseller Freight Cost]
)
SELECT
NON EMPTY {
[Date].[Calendar] * [Product].[Category]
,[Date].[Calendar].children * [Product].[Category]
} DIMENSION PROPERTIES children_cardinality, parent_unique_name ON COLUMNS,
NON EMPTY {
[CitySet], //<<changed here [Geography].[City],
[Geography].[City].children
}
DIMENSION PROPERTIES children_cardinality, parent_unique_name ON ROWS
FROM [Adventure Works]
WHERE (
[Measures].[Reseller Freight Cost]
)

EXISTING equivalent to HAVING

This works:
WITH
MEMBER [Measures].[CurrentDay] AS
AGGREGATE(
[Date].[Calendar].Currentmember,
[Measures].[Reseller Sales Amount]
)
MEMBER [Measures].[CurrentMonth] AS
AGGREGATE(
[Date].[Calendar].Currentmember.parent,
[Measures].[Reseller Sales Amount]
)
SELECT
NON EMPTY
{ [Measures].[CurrentDay],
[Measures].[CurrentMonth] }
ON COLUMNS,
NON EMPTY
{ [Date].[Calendar].[Date] }
HAVING [Measures].[CurrentDay]<>null //<<<<<<<<<<<<<<having line
ON ROWS
From [Adventure Works]
Returning the following from the version of Adventure Works that I have:
If I comment out the line HAVING [Measures].[CurrentDay]<>null then this happens:
Is there another way of eliminating the rows that are null for CurrentDay without using HAVING ?
I've tried using EXISTING without any success:
WITH
MEMBER [Measures].[CurrentDay] AS
AGGREGATE(
[Date].[Calendar].Currentmember,
[Measures].[Reseller Sales Amount]
)
MEMBER [Measures].[CurrentMonth] AS
AGGREGATE(
[Date].[Calendar].Currentmember.parent,
[Measures].[Reseller Sales Amount]
)
SELECT
NON EMPTY
{ [Measures].[CurrentDay],
[Measures].[CurrentMonth] }
ON COLUMNS,
NON EMPTY
{ EXISTING [Date].[Calendar].[Date] }
ON ROWS
From [Adventure Works]
EDIT
To run nsousa's solution in SSMS I need to nest the IIF like this:
WITH
MEMBER [Measures].[CurrentDay] AS
AGGREGATE(
[Date].[Calendar].Currentmember,
[Measures].[Reseller Sales Amount]
)
MEMBER [Measures].[CurrentMonth] AS
IIF(
ISEMPTY([Measures].[CurrentDay]),
NULL,
AGGREGATE(
[Date].[Calendar].Currentmember.parent,
[Measures].[Reseller Sales Amount]
)
)
SELECT
NON EMPTY
{ [Measures].[CurrentDay],
[Measures].[CurrentMonth] }
ON COLUMNS,
NON EMPTY
{ [Date].[Calendar].[Date] }
ON ROWS
From [Adventure Works]
You can redefine your measure:
WITH
MEMBER [Measure].[Not Null Reseller Sales Amount] AS
IIF( IsEmpty( [Measures].[Reseller Sales Amount] ), 0, [Measures].[Reseller Sales Amount] )
MEMBER [Measures].[CurrentDay] AS
AGGREGATE(
[Date].[Calendar].Currentmember,
[Measures].[Not Null Reseller Sales Amount]
)
MEMBER [Measures].[CurrentMonth] AS
AGGREGATE(
[Date].[Calendar].Currentmember.parent,
[Measures].[Not Null Reseller Sales Amount]
)
SELECT
NON EMPTY
{ [Measures].[CurrentDay],
[Measures].[CurrentMonth] }
ON COLUMNS,
NON EMPTY
{ [Date].[Calendar].[Date] }
ON ROWS
From [Adventure Works]

ssas 2005 mdx get total

I have this MDX query
select
{
[Measures].[Sold value]
,[Measures].[Units]
,[Measures].[Sales baskets]
,[Measures].[ATV]
,[Measures].[AUT]
} on columns
, filter(
nonempty(
{[Branch].[Branch].&[5] *[Receipt No - Sales].[Receipt No].[Receipt No]}
),
[Measures].[Sold value] >= 50
) on rows
from Rmis
where [Time].[Day].&[20131218]
Which generates following result:
How can I get the total of these measures of the above result set? The total should use the aggregation defined in the cube.
with set [rows] as
filter(
nonempty(
{[Branch].[Branch].&[5] *[Receipt No - Sales].[Receipt No].[Receipt No]}
),
[Measures].[Sold value] >= 50
)
member [Receipt No - Sales].[Receipt No].[Total] as
aggregate([rows])
select
{
[Measures].[Sold value]
,[Measures].[Units]
,[Measures].[Sales baskets]
,[Measures].[ATV]
,[Measures].[AUT]
} on columns
,
{ ([Branch].[Branch].&[5], [Receipt No - Sales].[Receipt No].[Total]) }
+
[rows]
on rows
from Rmis
where [Time].[Day].&[20131218]