How to establish in a mdx query 2 measures and a hierarchy - ssas

I Have this query:
SELECT NON EMPTY {
[Art].[Art].[Art].ALLMEMBERS * [Measures].[Costs] * [Measures].[Margin]
} ON COLUMNS
FROM [Model]
CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE,
FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
I get an error, stating that this cannot be done. My idea is to show, for each member, its cost and margin, as follows:
Article 1 | Article 2 | Article 3
cost | margin | cost | margin | cost | margin
Which would be the correct way? By the way, any good tutorial or website to learn about creating mdx queries?

Your query is crossjoining the measures together: [Measures].[Costs] * [Measures].[Margin] but your idea for the expected results is different. What you show in your expected result is a crossjoin of two sets: {Articles} * {Measures}
I suggest something more like this:
SELECT
{[Measures].[Costs], [Measures].[Margin]} ON COLUMNS,
NON EMPTY {[Art].[Art].[Art].ALLMEMBERS} ON ROWS
FROM [Model]
CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
Or if you want it all on the columns, like your expected result:
SELECT
NON EMPTY {[Art].[Art].[Art].ALLMEMBERS} *
{[Measures].[Costs], [Measures].[Margin]} ON COLUMNS
FROM [Model]
CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
For learning about MDX, I recommend the book "MDX Solutions" as a gentle introduction.

Related

Result of the Sum of all elements mdx query incorrect Analysis Service Cube

i got a weird issue with my olap cube by issuing a mdx query.
You can see that the following mdx query is generated by excel:
SELECT NON EMPTY Hierarchize({DrilldownLevel({[BuchungskreisWerk].[Quelle].[All]},,,INCLUDE_CALC_MEMBERS)})
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME ON COLUMNS , NON EMPTY
Hierarchize({DrilldownLevel({[BuchungskreisWerk].[Buchungskreis mit Text].[All]},,,INCLUDE_CALC_MEMBERS)})
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME ON ROWS FROM
(SELECT ({[BuchungskreisWerk].[Buchungskreis mit Text].&[48], [BuchungskreisWerk].[Buchungskreis mit Text].&[49], [BuchungskreisWerk].[Buchungskreis mit Text].&[207], [BuchungskreisWerk].[Buchungskreis mit Text].&[221]})
ON COLUMNS FROM [Bestbew_Global])
WHERE ([Measures].[Lagerbestand]) CELL PROPERTIES VALUE, FORMAT_STRING, LANGUAGE, BACK_COLOR, FORE_COLOR, FONT_FLAGS
The output table looks as follows:
Output in Excel
So as we can see the total of B1 and R3 are correct.
But the sum of all resulst, which should be B1+R3 is B1 only.
Anyone has an idea where this error could came from?

How do I reformat a measure in a mdx query

I have an MDX query running on SSAS instance. The amount that gets displayed as a currency with spaces and , in the column. eg R 1 200,10.
I do not want to change anything on the data warehouse but want to change the format in the MDX query so that the results are displayed in the column as 1200.10 (a straight numeric)
I have included the following code on top of the exiting MDX query that give the wrong format.
with
member [Measures].[Gross Amt Exc Base] as [Measures].[AMT] , FORMAT_STRING="###0.00"
This is the code i have created:
with
member [Measures].[Gross Amt Exc Base] as [Measures].[AMT] , FORMAT_STRING="###0.00"
SELECT NON EMPTY { [Measures].[Gross Amt Exc Base] } ON COLUMNS,
NON EMPTY {(StrToMember('[Tran Date].[Actual Date].&[' + Format(Now()-1,'yyyy-MM-dd') + 'T00:00:00]')
:StrToMember('[Tran Date].[Actual Date].&[' + Format(Now()-3,'yyyy-MM-dd') + 'T00:00:00]') *
[Dim Store].[Store Number].[Store Number].ALLMEMBERS *
[Dim SKU].[SKU Code].[SKU Code].ALLMEMBERS *
[Dim SKU].[Product Code].[Product Code].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM [Dolfin Dwh FTS] CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
I want to see 1200.10 but get the following error message
"Executing the query ...
The 'Gross Amt Exc Base' calculated member cannot be created because a member with the same name already exists.
Run complete"
Please can some one help me.

Using WITH in mdx to retrieve row names

I am executing the following MDX query in SSMS, which I have got from Profiler:
SELECT {
[Measures].[Dollar Amount],
[Measures].[Transaction Count]}
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME ON COLUMNS,
NON EMPTY Hierarchize({DrilldownLevel({[Retail Sales Date].[Month].[All]},,,INCLUDE_CALC_MEMBERS)})
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME ON ROWS
FROM [Retail Sales Cube]
WHERE ([Geography].[Retail Sales Location].[Country Name].&[Australia],[Retail Category].[Retail Category].[All])
CELL PROPERTIES VALUE, FORMAT_STRING, LANGUAGE, BACK_COLOR, FORE_COLOR, FONT_FLAGS
This produces the following results (snippet only):
The rows are months, and because of the method of retrieval, I need the months to also be displayed in a column.
So I tried this:
WITH
MEMBER [TheDate] AS [Retail Sales Date].[Month].CurrentMember.Name
SELECT {
[TheDate],
[Measures].[Dollar Amount],
[Measures].[Transaction Count]}
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME ON COLUMNS,
NON EMPTY Hierarchize({DrilldownLevel({[Retail Sales Date].[Month].[All]},,,INCLUDE_CALC_MEMBERS)})
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME ON ROWS
FROM [Retail Sales Cube]
WHERE ([Geography].[Retail Sales Location].[Country Name].&[Australia],[Retail Category].[Retail Category].[All])
CELL PROPERTIES VALUE, FORMAT_STRING, LANGUAGE, BACK_COLOR, FORE_COLOR, FONT_FLAGS
which would be fine, except that it also shows rows where there are null values, as follows:
I know there is NONEMPTY, but I don't know where I would put it. How can I get rid of the empty rows?
Perhaps the following expression would do the trick:
WITH
MEMBER [TheDate] AS
IIF( !isEmpty( [Dollar Amount] )
[Retail Sales Date].[Month].CurrentMember.Name,
null
)

Calculated measure hurting performance and returning many more rows

I have the following query which should be returning income split by country and date. It should also be including a count of the number of dates in the grouping. This would be useful for a calculation looking at an entire month of income/days. I'm finding that the calculated measure is causing all countries in the dimension to be returned regardless of if there's any income data for it. Is there any way to limit this so only countries with income are returned?
with
MEMBER [Measures].[group_day_count] as
COUNT(
Descendants(
[Date].[Date].currentmember, [Date].[Date].[Date]
)
)
SELECT NON EMPTY Hierarchize({DrilldownLevel({[Date].[Date].[All]},,,INCLUDE_CALC_MEMBERS)})
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME,
[Date].[Date].[Date].[Date Sort] ON COLUMNS ,
NON EMPTY CrossJoin(Hierarchize({DrilldownLevel({[Source Location].[Country Code].[All]},,,INCLUDE_CALC_MEMBERS)}),
{[Measures].[group_day_count],[Measures].[income]})
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME ON ROWS
FROM (SELECT ({[Date].[Date].&[2017-10-04], [Date].[Date].&[2017-10-05], [Date].[Date].&[2017-10-06], [Date].[Date].&[2017-10-07], [Date].[Date].&[2017-10-08], [Date].[Date].&[2017-10-09], [Date].[Date].&[2017-10-10]})
ON COLUMNS FROM [Placeholder])
CELL PROPERTIES VALUE, FORMAT_STRING, LANGUAGE, BACK_COLOR, FORE_COLOR, FONT_FLAGS
Try:
IIF([Measures].[Income],[Measures].[Days],NULL)

MDX Query Optimization

I have a pivot table generated in Excel. I need to use the same MDX query which is used in Excel, I have extracted the same query from Excel which is like this -
SELECT {[Measures].[OQ],[Measures].[RQ],[Measures].[SQ],[Measures].[SRQ]}
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME ON COLUMNS ,
CrossJoin(
CrossJoin(
CrossJoin(
CrossJoin(
CrossJoin(
CrossJoin(
CrossJoin(
Hierarchize({DrilldownLevel({[PO].[Date].[All]},,,INCLUDE_CALC_MEMBERS)}),
Hierarchize({DrilldownLevel({[PO].[Priority].[All]},,,INCLUDE_CALC_MEMBERS)})),
Hierarchize({DrilldownLevel({[POL].[Container].[All]},,,INCLUDE_CALC_MEMBERS)})),
Hierarchize({DrilldownLevel({[PO].[Name].[All]},,,INCLUDE_CALC_MEMBERS)})),
Hierarchize({DrilldownLevel({[POL].[Num].[All]},,,INCLUDE_CALC_MEMBERS)})),
Hierarchize({DrilldownLevel({[PO].[Warehouse].[All]},,,INCLUDE_CALC_MEMBERS)})),
Hierarchize({DrilldownLevel({[POL].[Status].[All]},,,INCLUDE_CALC_MEMBERS)})),
Hierarchize({DrilldownLevel({[POL].[Factor].[All]},,,INCLUDE_CALC_MEMBERS)}))
ON ROWS
FROM [Purchases] CELL PROPERTIES VALUE, FORMAT_STRING, LANGUAGE, BACK_COLOR, FORE_COLOR, FONT_FLAGS
This query returns about 3 lac records in excel, when I run this query in SSMS it gives error like "Server: The operation has been cancelled due to memory pressure.".
I am new to MDX, above query uses many CrossJoins, is there any way to optimize this query?
Thanks and Regards,
Amit Thakkar
I think its result maybe unusable almost for statistic reason
because of returning many rows.
but for optimization I suggest using
NONEMPTY
front of your crossjoin