I'm building an ssrs report with this MDX query:
SELECT
NON EMPTY { ([KeyWords Dim].[Keywords].[Keyword].ALLMEMBERS *
[Ad Dim].[Countries].[Countries].ALLMEMBERS *
[Creative Dim].[Creatives].[Title].ALLMEMBERS ) } ON ROWS,
[Measures].[Clicks] ON COLUMNS
FROM [CubeName]
WHERE ([Time Dim].[Day ID].&[20140701]:[Time Dim].[Day ID].&[20140701])
I want to add another where clause to get only result for specific countries, something like that:
Where [Getways Dim].[Countries].[Countries].ALLMEMBERS IN ([Getways Dim].[Country].[Countries].&["Germany"],[Getways Dim].[Country].[Countries].&["US"]...)
How to do the "IN" part?
Thanks
In MDX, you do not use IN, you specify a set. The easiest way to specify a set is to just a list of members on braces like this:
WHERE {
[Getways Dim].[Country].[Countries].&["Germany"],
[Getways Dim].[Country].[Countries].&["US"]
}
and to combine conditions on two different hierarchies like Time and country, you build a cross product like this (* is the cross product operator in MDX):
WHERE ([Time Dim].[Day ID].&[20140701]:[Time Dim].[Day ID].&[20140701])
*
{
[Getways Dim].[Country].[Countries].&["Germany"],
[Getways Dim].[Country].[Countries].&["US"]
}
Related
I am using copy activity in ADF in which i have following pseudo query:
SELECT
{
[Measures].[**************],
[Measures].[**************],
[Measures].[**************]
} ON COLUMNS,
NON EMPTY
{
[0CALWEEK].[LEVEL01].MEMBERS
}
DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM cubeName/ReportName
SAP VARIABLES [SAP_VARIABLE_NAME]
INCLUDING [0CALWEEK].[201905]
In the above i want to replace '201905' dynamically,there is no current function availabe to get WeekOfYear in ADF Expressions and functions OR can i use MDX Query to generate WeekOfYear
Take a look at this example how it changes value for a member value. Please note I have answerd if from phone so some syntax issue might exist.
With member measures.t
As
Case when
[0CALWEEK].[LEVEL01]. currentmember.name="'201905"
Then 1
Else
0
End
SELECT
{
[Measures].[t]
} ON COLUMNS,
NON EMPTY
{
[0CALWEEK].[LEVEL01].MEMBERS
} ON ROWS
FROM cubeName/ReportName
What is the difference between representing tuple in an mdx query as
[CF Type].[CF TYPE].&[6]
OR
[ValScen].[Scenario Type].&[Term Point Rates]
Can I use the &[number] and the &[actual string] format interchangeably? If the cube is generated by another system, can the &[6] be different for each generation in usual practice? Or is it safer to use StrToMember or StrToSet. But this is not efficient as per this article. To give some context, in my case I use it like in below pseudocode
SELECT NON EMPTY { [Measures].x} ON COLUMNS, NON EMPTY { (My Column1 * My Column2)} DIMENSION PROPERTIES MEMBER_CAPTION ON ROWS FROM ( SELECT ( { [CF Type].[CF TYPE].&[6] } ) ON COLUMNS FROM
( SELECT ( { [ValScen].[Scenario Type].&[Term Point Rates] } ) ON COLUMNS FROM [My Cube]]))
WHERE ( [ValScen].[Scenario Type].&[Term Point Rates], [CF Type].[CF TYPE].&[6] )
Those are members and not tuples. A Tuple would be surrounded by braces ().
I think they are interchangeable syntax if you’re using the caption such as .&[hello] and .[hello] but if you use the key then the ampersand is mandatory.
I'm looking for a way to integrate a previously retrieved list as an input for a FILTER in a MDX query. I currently have the following code:
segment_var = Segment,
mdxQ = "SELECT
NON EMPTY ( { [Measures].[AMT] * [Forecast Type].[Forecast Type].[Forecast Level 2] } ) DIMENSION PROPERTIES MEMBER_NAME ON COLUMNS,
NON EMPTY ( {
[Period].[Year Month Name].[Name] *
[PL Spec].[PL Spec].[Level 6 Code].allmembers
} ) ON ROWS
FROM (
SELECT ( { [Forecast Type].[Current Indicator].&[Y] } ) ON COLUMNS
FROM (
SELECT ( { [PL Spec].[PL Spec].[Level 1 Code].&[101] } ) ON COLUMNS
FROM [AIR]))
WHERE (
FILTER([Management Structure - Segment].[Management Structure - Segment].[MS Level 5].ALLMEMBERS , [Management Structure - Segment].[Management Structure - Segment].currentmember.name=""" & segment_var & """))",
Segment on row 1 used to be a single value parameter but I want to use a list of segments (listSegment) as a reference instead so the result filters multiple segments. I've tried WHERE IN solutions but I can't seem to get it to work. Any help would be appreciated.
Error:
Expression.Error: We cannot apply operator & to types Text and List.
Try to generate segment_var as
{[Management Structure - Segment].[Management Structure - Segment].[1], [Management Structure - Segment].[Management Structure - Segment].[2], ...}
Managed to solve the issue in the following way:
Make the list of values to be filtered in the query
Transpose and combine the list using ", "
Convert to single variable
Code:
Convert =
Table.ToList(
Table.Transpose(
Table.FromList(#"Distinct")),
Combiner.CombineTextByDelimiter(", ")),
Var = List.First(Convert)
I have this where clause in sql language:
where (cond1=1 or cond2=1) and cond3=1
How can I get this result in MDX with the slicing(condition into the where)?
{[cond1].&[1],[cond2].&[1]} /*and*/ {[cond3].&[1]}
Thanks
Try to use a subcube:
Select
-- YOUR SELECTED MEASURES AND DIMENSIONS
From
(
Select
{[cond1].&[1],[cond2].&[1]} on 0
,{[cond3].&[1]} on 1
-- ,{more slices} on x
From [CubeName]
)
Hope this help!
You can use subcube expression as stated above, but this is not the only option. If you use subcube, you would increase query performance greatly (assuming the fact you don't perform crossjoins in it).
You can also use general WHERE keyword after last expression that returns cube:
select
{ .. } on 0,
{ .. } on 1
from (select { [Dim1].[X].allmembers } on 0)
where ([Dim2].[Y].&[Y1])
Or:
select
{ .. } on 0,
{ .. } on 1
from (select { [Dim1].[X].allmembers } on 0)
where {[DimTime].[Time].[Year].&[2001] : [DimTime].[Time].[Year].&[2015]}
This is applied at the end of execution, which means performance may decrease. However, if you need to apply external filter to all axis, this is the option you need.
Another way to filter member values is using tuple expressions:
with member LastDateSale as ( (Tail(EXISTING [DimTime].[Time].[Dates].members,1), [Measures].[ActualSales]) )
This will take your DimTime axis, apply external filter, get the last element from it and calculate [ActualSales] for it, if possible.
I have following query for calculated member:
SUM(
EXCEPT([Policy].[Policy Status].[Policy Status],[Policy].[Policy Status].&[Void])
, [Measures].[CountPolicyEndorsesNull]
)
What I want is to include another EXCLUDE filter. I have tried following:
SUM(
{EXCEPT([Policy].[Policy Status].[Policy Status],[Policy].[Policy Status].&[Void])}
*
{EXCEPT([Invoice].[Invoice Status].[Invoice Status],[Invoice].[Invoice Status].&[Void])}
, [Measures].[CountPolicyEndorsesNull]
)
but it returns more result than the first query. Any ideas?
Your syntax is correct. The reasons it could be more are the following:
You have negative results in ([Invoice].[Invoice Status].&[Void], [Measures].[CountPolicyEndorsesNull])
You have a default member set on [Invoice].[Invoice Status].[Invoice Status].
Try returning the following query:
select
[Measures].[CountPolicyEndorsesNull]
on columns,
{[Invoice].[Invoice Status].DefaultMember,
[Invoice].[Invoice Status].&[Void]
}
on rows
from [CubeName]
That will get you your culprit.