I trying to execute below MDX query it took more than 10 mins is there any possibility to improve performance on below query.
WITH
MEMBER PatientName AS [DimPatient].[Full Name].CurrentMember.Member_Caption
MEMBER PatientAge AS [DimPatient].[Age].CurrentMember.Member_Caption
MEMBER PatientGender AS [DimPatient].[Gender].CurrentMember.Member_Caption
MEMBER PatientMRN AS [DimPatient].[Medical Record Number].CurrentMember.Member_Caption
MEMBER [PCPList] AS Generate ([DimPCP].[Provider Key].[Provider Key].MEMBERS,
IIF([Measures].[CCMPatientCnt] <> 0,[DimPCP].[Provider Key].CurrentMember.Member_Caption + '',NULL))
MEMBER CareTeamList AS [DimCareTeam].[CareTeamName].CurrentMember.Member_Caption
MEMBER ConditionList AS [DimCondition].[Condition Name].CurrentMember.Member_Caption
SELECT ORDER(NonEmpty (([DimPatient].[Patient Key].[Patient Key],
[DimCareTeam].[CareTeamName].[CareTeamName],
[DimCondition].[Condition Name].[Condition Name]),
{[Measures].[CCMPatientCnt]} ),
([Measures].[patientName]),BASC) ON 1 ,
{ [Measures].[PatientName] ,
[Measures].[PatientAge] ,
[Measures].[PatientGender] ,
[Measures].[PatientMRN] ,
[Measures].[Num Of Minutes] ,
[PCPList] ,[CareTeamList] ,
[ConditionList] } ON 0
FROM [NavigateCube]
WHERE ( [DimManagedPopulation].[ManagedPopulationKey].&[4332],
[DimAnchorDate].[Date Key].&[20180731])
enter image description here
Related
This is my sql code - I want to convert it into an mdx query.
Also those results set use into power bi report.
I am unable to write this sql query into mdx query. Can anybody help me?
Select * From(
Select
dense_RANK()over(partition by t.MonthName order by t.amount desc)rank
,t.*
From(
Select DSP.SalesPointShortName ,dd.MonthName
,SUM(fs.salesAmount)Amount
From FactSales FS
INNER JOIN DimDate dd on fs.DateKey=dd.DateKey
INNER JOIN DimSalesPoint DSP on DSP.SalesPointID=FS.SalesPointID
group by dsp.SalesPointShortName ,dd.MonthName
)as t
)as f where f.rank=1
My expected output is:
Lots of google searching i have the answer from below link
After following this link desire results comes.
https://bipassion.wordpress.com/2013/06/22/mdx-dense-rank/
`
WITH SET [Sorted Models] AS
// For each month get Top 25 records, choosed a Top 25 from business case
Generate (
[Dim Date].[Month Name].[Month Name].Members,
TopCount
( nonempty(
{
[Dim Date].[Month Name].CurrentMember
* [Dim Sales Point].[SalesPoint].[Sales Point Short Name].MEMBERS
}
,[Measures].[Sales Amount]
)
, 1
,[Measures].[Sales Amount]
)
)
//Select
//[Measures].[Sales Amount] on 0,[Sorted Models] on 1
//From [MdCubeTest]
//where [Dim Product Group Item].[Sub Category Name].&[Bag]
MEMBER [Measures].[Rank] AS
// Get the Rank of current member Tuple to Current Month Set
// Do not use Sorted Models set due to dynamic for each set
Rank (
(
[Dim Date].[Month Name].CurrentMember
, [Dim Sales Point].[SalesPoint].CurrentMember
)
, Generate ( [Dim Date].[Month Name].CurrentMember,
TopCount
( nonempty(
{ [Dim Date].[Month Name].CurrentMember
* [Dim Sales Point].[SalesPoint].[Sales Point Short Name]
}
,[Measures].[Sales Amount]
)
, 25
,[Measures].[Sales Amount]
)
)
, [Measures].[Sales Amount]
)
MEMBER [Measures].[Previous Set Index] AS
// Get the Set Index using Rank
(
[Measures].[Rank] - 2
)
MEMBER [Measures].[Dense Rank] AS
// Get the Dense Rank using the Index position value
CASE
WHEN [Measures].[Rank] = 1
THEN 1
ELSE
(
[Sorted Models].Item([Measures].[Previous Set Index]),
[Measures].[Dense Rank]
)
+
Iif
(
(
[Sorted Models].Item([Measures].[Previous Set Index]),
[Measures].[Sales Amount]
)
=
[Measures].[Sales Amount]
,0
,1
)
End
SELECT
{
[Measures].[Sales Amount]
, [Measures].[Rank]
, [Measures].[Dense Rank]
//, [Measures].[Previous Set Index]
} ON rows
,NON EMPTY
{
// FILTER Can be used to get the TOP 3 using DENSE RANK
FILTER (
[Sorted Models]
, [Measures].[Dense Rank] <=1
)
} ON columns
FROM [MdCubeTest]
where [Dim Product Group Item].[Sub Category Name].&[Bag]`
I am still getting to grips with MDX and I am looking for some help. Here is my MDX query:
CREATE MEMBER CURRENTCUBE.[Measures].[Fake]
AS
IIF(
(
(
[Sales Data].[Ship-to No].CurrentMember
,[Sales Data].[Price Type].&[Core]
,[Measures].[Sales - Local Currency]
)
/ (
[Sales Data].[Ship-to No].CurrentMember,
[Sales Data].[Price Type].[(All)].[ALL],
[Measures].[Sales - Local Currency]
)
) > 0.9
,1
,NULL
),
VISIBLE = 1;
CREATE MEMBER CURRENTCUBE.[Measures].[Test Calc]
AS
SUM(
Descendants(
[Sales Data].[Ship-to No].CurrentMember
,[Sales Data].[Ship-to No].[Ship-to No]
),
[Measures].[Fake]
),
VISIBLE = 1;
SalesData is the fact table and the basic calculation is to count the number of customers that have sales of more than 90% of the price type "Core".
The query currently takes around 5 seconds to complete but I think this can be faster if I don't use CurrentMember according to http://sqlblog.com/blogs/mosha/archive/2008/07/29/product-volatility-optimizing-mdx-with-mdx-studio.aspx
But I don't know where to begin in changing this, can anyone help me make this more efficient?
If you delete currentmember from the first measure does it make any difference?
CREATE MEMBER CURRENTCUBE.[Measures].[Fake]
AS
IIF(
(
(
[Sales Data].[Price Type].&[Core]
,[Measures].[Sales - Local Currency]
)
/ (
[Sales Data].[Price Type].[(All)].[ALL],
[Measures].[Sales - Local Currency]
)
) > 0.9
,1
,NULL
),
VISIBLE = 1;
In respect of the currentmember you use in the second measure maybe EXISTING will suffice:
CREATE MEMBER CURRENTCUBE.[Measures].[Test Calc]
AS
SUM(
EXISTING [Sales Data].[Ship-to No].[Ship-to No].MEMBERS
,[Measures].[Fake]
),
VISIBLE = 1;
This query is taking too much of time for executing result set, is there any way to optimise the query
WITH MEMBER PatientName AS [DimPatient].[Full Name].CurrentMember.Member_Caption
MEMBER PatientAge AS [DimPatient].[Age].CurrentMember.Member_Caption
MEMBER PatientGender AS [DimPatient].[Gender].CurrentMember.Member_Caption
MEMBER PatientMRN AS [DimPatient].[Medical Record Number].CurrentMember.Member_Caption
MEMBER PCPList AS [DimPCP].[Provider Key].CurrentMember.Member_Caption
MEMBER CareTeamList AS [DimCareTeam].[CareTeamName].CurrentMember.Member_Caption
MEMBER ConditionList AS [DimCondition].[Condition Name].CurrentMember.Member_Caption
SELECT (([DimPatient].[Patient Key].[Patient Key],
[DimPCP].[Provider Key].[Provider Key],
[DimCareTeam].[CareTeamName].[CareTeamName],
[DimCondition].[Condition Name].[Condition Name])) ON 1 ,
{ [Measures].[PatientName] ,
[Measures].[PatientAge] ,
[Measures].[PatientGender] ,
[Measures].[PatientMRN] ,
[Measures].[Num Of Minutes] ,
[PCPList] ,[CareTeamList] ,
[ConditionList] } ON 0 FROM [NavigateCube]
WHERE ( [DimManagedPopulation].[ManagedPopulationKey].&[5059],[DimAnchorDate].[Date Key].&[20160930] )
Can you try the following? There is no need to build measures to return dimension captions. And a NON EMPTY should speed it up by returning only combinations of dimensions that make sense (combinations with Num of Minutes I assume):
SELECT NON EMPTY (([DimPatient].[Patient Key].[Patient Key],
[DimPatient].[Full Name].[Full Name],
[DimPatient].[Age].[Age],
[DimPatient].[Gender].[Gender],
[DimPatient].[Medical Record Number].[Medical Record Number],
[DimPCP].[Provider Key].[Provider Key],
[DimCareTeam].[CareTeamName].[CareTeamName],
[DimCondition].[Condition Name].[Condition Name])) ON 1 ,
{ [Measures].[Num Of Minutes] } ON 0
FROM [NavigateCube]
WHERE ( [DimManagedPopulation].[ManagedPopulationKey].&[5059],[DimAnchorDate].[Date Key].&[20160930] )
I need to add a column in existing MDX and its values should be 1,1,1,1, and 2,2,2 like below.
Top line income 1
Products (GL) 1
Net Interest Income (NII) 1
Non Interest Revenue (NIR) 1
Products ( Non GL) 1
Net Interest Income (NII) 1
Non Interest Revenue (NIR) 1
WIP (No. of Prospects Logged) 2
WIP (Prospects Total Amount) Exposure 2
WIP (Prospects Total Amount) Deposits 2
Accepted Payouts in Progress (volume) 2
Accepted Payouts in Progress Exposure 2
Approval Rate (%) 2
Rejection Rate (Not taken up) (%) 2
...
...
How to achieve this in existing query?
MDX:
WITH
MEMBER [Measures].[Measure_Key] AS
[ScoreCardMeasures].[ScoreCard].Member_Key
MEMBER [Measures].[Measure_Group_Key] AS
[ScoreCardMeasures].[ScoreCard].Parent.Member_Key
MEMBER [Measures].[Structure_Level] AS
[CustomerStructure].[Provincial Structure].LEVEL_NUMBER
SET [ReportLevel] AS
Filter
(
[Report Levels].[Report Level].[Report Level]
,
Cint([Report Levels].[Report Level].Properties("Structure Level"))
=
Cint([Measures].[Structure_Level])
)
MEMBER [Measures].[Sequence] AS
[ScoreCardMeasures].[ScoreCard].Properties("Sequence")
MEMBER [Measures].[Indent] AS
[ScoreCardMeasures].[ScoreCard].Properties("Font Indent")
MEMBER [Measures].[Weight] AS
[ScoreCardMeasures].[ScoreCard].Properties("Font Weight")
MEMBER [Measures].[Header] AS
[ScoreCardMeasures].[ScoreCard].Properties("Values Header")
MEMBER [Measures].[Header1Caption] AS
[ScoreCardMeasures].[ScoreCard].Properties("Header Name1")
MEMBER [Measures].[Header2Caption] AS
[ScoreCardMeasures].[ScoreCard].Properties("Header Name2")
MEMBER [Measures].[Header3Caption] AS
[ScoreCardMeasures].[ScoreCard].Properties("Header Name3")
MEMBER [Measures].[Actual] AS
[Measures].[Measure Value]
MEMBER [Measures].[Target] AS
[Measures].[Measure Target]
MEMBER [Measures].[Average] AS
[Measures].[Average Value]
SELECT
{
[Measures].[Measure_Key]
,[Measures].[Measure_Group_Key]
,[Measures].[Structure_Level]
,[Measures].[Sequence]
,[Measures].[Indent]
,[Measures].[Weight]
,[Measures].[Header]
,[Measures].[Header1Caption]
,[Measures].[Header2Caption]
,[Measures].[Header3Caption]
,[Measures].[Actual]
,[Measures].[Target]
,[Measures].[Average]
} ON COLUMNS
,{
Filter
(
[ReportLevel]
*
Order
(
Descendants
(
StrToMember(#Financial_Measure)
,[ScoreCardMeasures].[ScoreCard].[Measure Code]
,LEAVES
)
,[Measures].[Sequence]
,ASC
)
,
[Measures].[Active Indicator] <> 0
)
} ON ROWS
FROM [ScoreCard]
WHERE
(
StrToMember(#SiteStructure)
,StrToMember(#Time)
);
I don't fully understand how you decide if it should be a 1 or a 2 - the question does not make it clear.
If you just want it hard-coded into the mdx then this might be an approach:
WITH
MEMBER [Measures].[Measure_Key] AS
[ScoreCardMeasures].[ScoreCard].Member_Key
MEMBER [Measures].[Measure_Group_Key] AS
[ScoreCardMeasures].[ScoreCard].Parent.Member_Key
MEMBER [Measures].[Structure_Level] AS
[CustomerStructure].[Provincial Structure].LEVEL_NUMBER
SET [ReportLevel] AS
Filter
(
[Report Levels].[Report Level].[Report Level]
,
Cint([Report Levels].[Report Level].Properties("Structure Level"))
=
Cint([Measures].[Structure_Level])
)
MEMBER [Measures].[Sequence] AS
[ScoreCardMeasures].[ScoreCard].Properties("Sequence")
MEMBER [Measures].[Indent] AS
[ScoreCardMeasures].[ScoreCard].Properties("Font Indent")
MEMBER [Measures].[Weight] AS
[ScoreCardMeasures].[ScoreCard].Properties("Font Weight")
MEMBER [Measures].[Header] AS
[ScoreCardMeasures].[ScoreCard].Properties("Values Header")
MEMBER [Measures].[Header1Caption] AS
[ScoreCardMeasures].[ScoreCard].Properties("Header Name1")
MEMBER [Measures].[Header2Caption] AS
[ScoreCardMeasures].[ScoreCard].Properties("Header Name2")
MEMBER [Measures].[Header3Caption] AS
[ScoreCardMeasures].[ScoreCard].Properties("Header Name3")
MEMBER [Measures].[Actual] AS
[Measures].[Measure Value]
MEMBER [Measures].[Target] AS
[Measures].[Measure Target]
MEMBER [Measures].[Average] AS
[Measures].[Average Value]
MEMBER [Measures].[1or2] AS
CASE
WHEN
[ScoreCardMeasures].[ScoreCard].CurrentMember
IS
[ScoreCardMeasures].[ScoreCard].[Measure Code].[Top Line Income]
THEN 1
WHEN
[ScoreCardMeasures].[ScoreCard].CurrentMember
IS
[ScoreCardMeasures].[ScoreCard].[Measure Code].[Products (GL)]
THEN 1
WHEN
[ScoreCardMeasures].[ScoreCard].CurrentMember
IS
[ScoreCardMeasures].[ScoreCard].[Measure Code].[WIP (No. of Prospects Logged)]
THEN 2
WHEN
[ScoreCardMeasures].[ScoreCard].CurrentMember
IS
[ScoreCardMeasures].[ScoreCard].[Measure Code].[WIP (Prospects Total Amount) Exposure]
THEN 2
END
SELECT
{
[Measures].[Measure_Key]
,[Measures].[Measure_Group_Key]
,[Measures].[Structure_Level]
,[Measures].[Sequence]
,[Measures].[Indent]
,[Measures].[Weight]
,[Measures].[Header]
,[Measures].[Header1Caption]
,[Measures].[Header2Caption]
,[Measures].[Header3Caption]
,[Measures].[Actual]
,[Measures].[Target]
,[Measures].[Average]
,[Measures].[1or2]
} ON COLUMNS
,{
Filter
(
[ReportLevel]
*
Order
(
Descendants
(
StrToMember(#Financial_Measure)
,[ScoreCardMeasures].[ScoreCard].[Measure Code]
,LEAVES
)
,[Measures].[Sequence]
,ASC
)
,
[Measures].[Active Indicator] <> 0
)
} ON ROWS
FROM [ScoreCard]
WHERE
(
StrToMember(#SiteStructure)
,StrToMember(#Time)
);
In a SSAS 2005 cube.
I have a product dimension, it has a attribute: sp (selling price)
I want to list the sp along with other facts for products. But the query below returns null for sp. Idea?
with member [measures].[sp] as
[Products].[Current Sp].currentmember
select {
[Measures].[Sold value]
, [measures].[sp]
} on 0
,
nonempty(
{[Sales order details].[Receipt No].[Receipt No].allmembers}
*{[Sales order details].[Line No].[Line No].allmembers}
*{[Products].[Product code].[Product code].allmembers}
, [Measures].[Sold value]
) on 1
from (
select [Time].[Day].&[20140430] on 0 from (
select [Branch].[Branch].&[2] on 0 from (
select [Sales order details].[Receipt No].[680207] on 0 from [Rmis]
)
)
)
update:
this is the final working query. I added [Products].[SKU].[SKU] because otherwise Current Sp returns 'All' (the null in original question is because of not using .Member_value). Current Sp and Product code are not related while they both related to [Products].[SKU].
with member [measures].[sp] as
[Products].[Current Sp].currentmember.MEMBER_value
select {
[Measures].[Sold value]
, [measures].[sp]
} on 0
,
nonempty(
{[Sales order details].[Receipt No].[Receipt No].allmembers}
*{[Sales order details].[Line No].[Line No].allmembers}
*{[Products].[Product code].[Product code].allmembers}
*{[Products].[SKU].[SKU]}
, [Measures].[Sold value]
) on 1
from (
select [Time].[Day].&[20140430] on 0 from (
select [Branch].[Branch].&[2] on 0 from (
select [Sales order details].[Receipt No].[680207] on 0 from [Rmis]
)
)
)
with member [measures].[sp] as
[Products].[Current Sp].CurrentMember.MemberValue
very close...just need to specify which property to display