I have built this query through BIDS Query Designer. But I want to optimize this query by removing SELECTS inside outermost FROM Clause and having only cube in from clause and rest filter on where or filter clause:
SELECT { [Measures].[User ID Distinct Count], [Measures].[Post Count], [Measures].[Like Count], [Measures].[Comment Count], [Measures].[Impressions Master Count] } ON COLUMNS,
NON EMPTY { ([Section Master].[Section Name].[Section Name].ALLMEMBERS * [Post Master].[Post Name].[Post Name].ALLMEMBERS * [Post Master].[SP Insert Date].[SP Insert Date].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM ( SELECT ( STRTOSET(#SectionMasterSectionName) ) ON COLUMNS
FROM ( SELECT ( STRTOMEMBER(#FromDimDateDate) : STRTOMEMBER(#ToDimDateDate) ) ON COLUMNS
FROM [AnalyticsCube]))
CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
I am quite new in MDX and don't know much in regards to MDX query optimization. And Because of that I also don't know that this is the Optimized version of query or there is still scope for optimization in this. My cube structure is shown in Image.
I have Update my old query by doing some changes in Row and Column Part, but still stuck with From Clause part
SELECT { [Measures].[User ID Distinct Count],
[Measures].[Post Count],
[Measures].[Like Count],
[Measures].[Comment Count],
[Measures].[Impressions Master Count] } ON COLUMNS,
NON EMPTY { ([Section Master].[Section Name].CHILDREN) *
([Post Master].[Post Name].CHILDREN, [Post Master].[SP Insert Date].CHILDREN ) } ON ROWS
FROM ( SELECT ( STRTOSET(#SectionMasterSectionName) ) ON COLUMNS
FROM ( SELECT ( STRTOMEMBER(#FromDimDateDate) : STRTOMEMBER(#ToDimDateDate) ) ON COLUMNS
FROM [AnalyticsCube]))
This would be the initial simplification:
SELECT
{
[Measures].[User ID Distinct Count]
,[Measures].[Post Count]
,[Measures].[Like Count]
,[Measures].[Comment Count]
,[Measures].[Impressions Master Count]
} ON COLUMNS
,NON EMPTY
{
[Section Master].[Section Name].Children
*
(
[Post Master].[Post Name].Children
,[Post Master].[SP Insert Date].Children
)
} ON ROWS
FROM
(
SELECT
StrToSet(#SectionMasterSectionName) ON 0,
StrToMember(#FromDimDateDate) : StrToMember(#ToDimDateDate) ON 1
FROM [AnalyticsCube]
);
Then it seems odd to me that you don't move StrToSet(#SectionMasterSectionName) into the main SELECT clause:
SELECT
{
[Measures].[User ID Distinct Count]
,[Measures].[Post Count]
,[Measures].[Like Count]
,[Measures].[Comment Count]
,[Measures].[Impressions Master Count]
} ON COLUMNS
,NON EMPTY
{
StrToSet(#SectionMasterSectionName)
*
(
[Post Master].[Post Name].Children
,[Post Master].[SP Insert Date].Children
)
} ON ROWS
FROM
(
SELECT
StrToMember(#FromDimDateDate) : StrToMember(#ToDimDateDate) ON 0
FROM [AnalyticsCube]
);
Logically it is slightly different but you could then think about using a WHERE clause rather than a SUB-SELECT:
SELECT
{
[Measures].[User ID Distinct Count]
,[Measures].[Post Count]
,[Measures].[Like Count]
,[Measures].[Comment Count]
,[Measures].[Impressions Master Count]
} ON COLUMNS
,NON EMPTY
{
StrToSet(#SectionMasterSectionName)
*
(
[Post Master].[Post Name].Children
,[Post Master].[SP Insert Date].Children
)
} ON ROWS
FROM [AnalyticsCube]
WHERE
StrToMember(#FromDimDateDate) : StrToMember(#ToDimDateDate);
Related
I have MDX query:
SELECT NON EMPTY { [Measures].[Revenue] } ON COLUMNS, NON EMPTY {( [DimDates].[YearMonthNum].[YearMonthNum].ALLMEMBERS )}
DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM ( SELECT ( { [TransactionsData].[FirstYearMonth].&[2020-01] } )
ON COLUMNS FROM ( SELECT ( { [TransactionsDataExtra].[Cluster].[All] } )
ON COLUMNS FROM ( SELECT ( { [TransactionsDataExtra].[Campaign].[All] } )
ON COLUMNS FROM ( SELECT ( { [TransactionsData].[RevenueGenerating].[All] } )
ON COLUMNS FROM ( SELECT ( { [TransactionsData].[Product].[All] } )
ON COLUMNS FROM ( SELECT ( { [TransactionsDataExtra].[Channel].[All] } )
ON COLUMNS FROM (SELECT ( { [TransactionsDataExtra].[Custom4].[All] } )
ON COLUMNS FROM (SELECT ( { [TransactionsDataExtra].[Custom5].[All] } )
ON COLUMNS FROM (SELECT ( { [TransactionsDataExtra].[Custom6].[All] } )
ON COLUMNS FROM (SELECT ( { [TransactionsData].[ClientId].&[2] } )
ON COLUMNS FROM [Model]))))))))))
WHERE ( [TransactionsDataExtra].[Channel].[All],
[TransactionsData].[Product].[All],
[TransactionsData].[RevenueGenerating].[All], [TransactionsDataExtra].[Campaign].[All],
[TransactionsData].[FirstYearMonth] <= ['2020-01'],
[TransactionsDataExtra].[Cluster].[All], [TransactionsData].[ClientId].&[2] )
CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING,
FONT_NAME, FONT_SIZE, FONT_FLAGS
I want to get results where e.g. Custom6 is NULL, or Custom5 is NULL or both of them, or any other filter, or Custom5[NULL, Value]
but I've been struggling to find how to do that and where in the query add changes... I tried passing nothing like: [TransactionsDataExtra].[Cluster].&[] but that didn't return anything at all. Could anyone help me out?
I also looked up ISEMPTY but can't figure out how to add it..
Fo anyone struggling in the future like noob me use this:
[DataExtra].[Cluster].& instead [DataExtra].[Cluster].&[]
also, check this amazing Excel extension to view queries: https://olappivottableextensions.github.io/#view-pivottable-mdx
I need two join two queries, I tried with members but it didn't work. I am new to MDX, please let me know if there a way of doing this. Error is due to list in the calculated member.
SELECT NON EMPTY { [RR TYPE].[Item].[Item].ALLMEMBERS * [Measures].[Unit Value] } ON COLUMNS,
NON EMPTY { ([FFS].[FFSCD].[FFSCD].ALLMEMBERS) } ON ROWS
FROM [GLCube]
WHERE ( [Location].[Site Name].&[Sandbox]
, [LT DT].[DATE HIERARCHY].[YEAR].&[2010]
,-{ [Ledger].[ID].&[A1],[Ledger].[ID].&[A2] ,[Ledger].[ID].&[A3]} )
SELECT NON EMPTY { [RT TYPE].[Item].[Item].ALLMEMBERS * [Measures].[Price Value] } ON COLUMNS,
NON EMPTY { ([FFS].[FFSCD].[FFSCD].ALLMEMBERS) } ON ROWS
FROM (SELECT [CCTYPE].[Desc].&[FCD] ON COLUMNS
FROM [GLCube])
WHERE ( [Location].[Site Name].&[Sandbox]
, [LT DT].[DATE HIERARCHY].[YEAR].&[2010])
Combined query
WITH MEMBER [Measures].[Unit Value]] AS
(-{[Ledger].[ID].&[A1],[Ledger].[ID].&[A2] ,[Ledger].[ID].&[A3]},[Measures].[Unit Value])
MEMBER [Measures].[Price Value] AS
( [CCTYPE].[Desc].&[FCD],[Measures].[Price Value] )
SELECT NON EMPTY {[Measures].[Unit Value],[Measures].[Price Value]} ON COLUMNS,
NON EMPTY { ([FFS].[FFSCD].[FFSCD].ALLMEMBERS} ON ROWS
FROM [GLCube]
WHERE ( [Location].[Site Name].&[Sandbox]
, [LT DT].[DATE HIERARCHY].[YEAR].&[2010])
Expected Output
WITH
MEMBER [Measures].[Filtered Unit Value] as
Aggregate(
-{ [Ledger].[ID].&[A1],[Ledger].[ID].&[A2] ,[Ledger].[ID].&[A3]},
[Measures].[Unit Value]
)
SELECT NON EMPTY
{
[RR TYPE].[Item].[Item].ALLMEMBERS
* {[RT TYPE].[Item].[All]}
* { [CCTYPE].[Desc].[All]}
* [Measures].[Filtered Unit Value]
}
+
{
{[RR TYPE].[Item].[All]}
* [RT TYPE].[Item].[Item].ALLMEMBERS
* { [CCTYPE].[Desc].&[FCD]}
* [Measures].[Price Value]
}
ON COLUMNS,
NON EMPTY { ([FFS].[FFSCD].[FFSCD].ALLMEMBERS) } ON ROWS
FROM [GLCube]
WHERE ( [Location].[Site Name].&[Sandbox]
, [LT DT].[DATE HIERARCHY].[YEAR].&[2010]
)
I want to make calculation in olap cube in ssas. This will be "avg sku by outlets".
There is my expression:
CREATE
MEMBER CURRENTCUBE.[Measures].[Avg Prod Art Id Distinct Count By OldcID] AS
Avg
(
Descendants
(
[dimOutlets].[OLDC ID].CurrentMember
,[dimOutlets].[OLDC ID].[OLDC ID]
)
,[Measures].[Prod Art Id Distinct Count]
);
It works fine, but when I tried to add some logic to it and something went wrong. I want to filter some docs by status or type.
This is what I did:
CREATE
MEMBER CURRENTCUBE.[Measures].[test Calculated Member] AS
Avg
(
NonEmpty
(
NonEmpty
(
{
[dimInvoice].[Doc Type].&[0]
,[dimInvoice].[Doc Type].&[1]
,[dimInvoice].[Doc Type].&[2]
,[dimInvoice].[Doc Type].&[3]
,[dimInvoice].[Doc Type].&[7]
,[dimInvoice].[Doc Type].[All].UnknownMember
}
,{
[dimInvoice].[Status].&[1]
,[dimInvoice].[Status].&[2]
,[dimInvoice].[Status].&[3]
,[dimInvoice].[Status].&[4]
,[dimInvoice].[Status].[All].UnknownMember
}
)
,Descendants
(
[dimOutlets].[OLDC ID].CurrentMember
,[dimOutlets].[OLDC ID].[OLDC ID]
)
)
,[Measures].[Prod Art Id Distinct Count]
) ;
When I try to test this on browser in visual studio, it thinks for a long time and I do not receive a reply.
Is there a best and fast way to do this?
PS. Sorry about my English.
This is work (thanks whytheq), but slowly and now i find solution to do this more faster. Wondering whether there is a possibility to do it a measure of the cube?
CREATE DYNAMIC SET CURRENTCUBE.[DocTypesSet]
AS nonempty
(
{
[dimInvoice].[Doc Type].&[0]
,[dimInvoice].[Doc Type].&[1]
,[dimInvoice].[Doc Type].&[2]
,[dimInvoice].[Doc Type].&[3]
,[dimInvoice].[Doc Type].&[7]
,[dimInvoice].[Doc Type].[All].UnknownMember
}
*{
[dimInvoice].[Status].&[1]
,[dimInvoice].[Status].&[2]
,[dimInvoice].[Status].&[3]
,[dimInvoice].[Status].&[4]
,[dimInvoice].[Status].[All].UnknownMember
}
*Descendants
(
[dimOutlets].[OLDC ID].CurrentMember
,[dimOutlets].[OLDC ID].[OLDC ID]
)
)
CREATE MEMBER CURRENTCUBE.[Measures].[test msr]
AS Sum(DocTypesSet,[Measures].[Prod Art Id Distinct Count] )
Maybe move the set out into a named set:
CREATE
SET CURRENTCUBE.[DocTypes] AS
NonEmpty
(
NonEmpty
(
{
[dimInvoice].[Doc Type].&[0]
,[dimInvoice].[Doc Type].&[1]
,[dimInvoice].[Doc Type].&[2]
,[dimInvoice].[Doc Type].&[3]
,[dimInvoice].[Doc Type].&[7]
,[dimInvoice].[Doc Type].[All].UnknownMember
}
,{
[dimInvoice].[Status].&[1]
,[dimInvoice].[Status].&[2]
,[dimInvoice].[Status].&[3]
,[dimInvoice].[Status].&[4]
,[dimInvoice].[Status].[All].UnknownMember
}
)
,Descendants
(
[dimOutlets].[OLDC ID].CurrentMember
,[dimOutlets].[OLDC ID].[OLDC ID]
)
);
CREATE
MEMBER CURRENTCUBE.[Measures].[test Calculated Member] AS
Avg
(
[DocTypes]
,[Measures].[Prod Art Id Distinct Count]
) ;
This is my MDX Query.
select
{
[Measures].[Quantity],
[Measures].[Net Sales]
}
on columns,
NON EMPTY
{(
[Products].[Item Description].children,
[Calendar].[Date].[Date]
)}
on rows
from
(
select
{
[Calendar].[Date].&[2015-03-23T00:00:00],
[Calendar].[Date].&[2015-03-22T00:00:00],
[Calendar].[Date].&[2015-03-21T00:00:00]
}
ON columns
FROM [SalesReport])
This gives the sales records in quantity and net sales as expected. We need now to sort it to get the item which has the highest quantity in first. In other words, we're looking to apply 'descending' sort here.
I tried all order method which gives me error. Can you please help me to get my wish done?
Have you tried the below ?
select
{
[Measures].[Quantity],
[Measures].[Net Sales]
}
on columns,
NON EMPTY
ORDER((
[Products].[Item Description].children,
[Calendar].[Date].[Date]
), [Measures].[Quantity], DESC)
on rows
from
(
select
{
[Calendar].[Date].&[2015-03-23T00:00:00],
[Calendar].[Date].&[2015-03-22T00:00:00],
[Calendar].[Date].&[2015-03-21T00:00:00]
}
ON columns
FROM [SalesReport])
Second attempt [WORKING SOLUTION]
select
{
[Measures].[Quantity],
[Measures].[Net Sales]
}
on columns,
NON EMPTY
ORDER((
[Products].[Item Description].children
), [Measures].[Quantity], DESC)
*[Calendar].[Date].[Date]
on rows
from
(
select
{
[Calendar].[Date].&[2015-03-23T00:00:00],
[Calendar].[Date].&[2015-03-22T00:00:00],
[Calendar].[Date].&[2015-03-21T00:00:00]
}
ON columns
FROM [SalesReport])
If you wanted to further order the inner group you could do this:
SELECT
{
[Measures].[Quantity],
[Measures].[Net Sales]
}
ON 0,
NON EMPTY
GENERATE(
ORDER(
[Products].[Item Description].children
,[Measures].[Quantity], BDESC)
,
ORDER(
[Products].[Item Description].CURRENTMEMBER //<< possibly [Products].CURRENTMEMBER
*
{[Calendar].[Date].[Date].Members}
,[Measures].[Quantity], BDESC))
ON 1
FROM
(
SELECT
{
[Calendar].[Date].&[2015-03-23T00:00:00],
[Calendar].[Date].&[2015-03-22T00:00:00],
[Calendar].[Date].&[2015-03-21T00:00:00]
}
ON 0
FROM [SalesReport]
);
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]
)