ssas mdx: query gone wrong - ssas

I'm getting the error: Query (9, 7) The '[Total Earnings]' member was not found in the cube when the string, [Measures].[Total Earnings], was parsed.
-- common enough, but I just don't see where in the query. Hopefully one of you will spot it, or have a better approach Here's what I have:
with
member measures.[Total all Earnings] as [Total Earnings]
(measures.[Total GS Earned]) + (measures.[Total DSE Earned]) + (measures. [Total Shares Earned])
set [Top 10 Interstate Earnings] as
topcount
(
{Stores.[Interstate]. [Interstate].members},
10,
(Measures.[Total Earnings], [Time].[C Year].[2011])
)
select
{([Measures].[Total Earnings])} on columns,
{[Top 10 Interstate Earnings]} on rows
from LoyaltyMeasurements
Where (Time.[C Year].[2012]);

I am a dufus... never mind. I didn't see until I pasted it!
the first line should be as follows for the calculated member:
with
member measures.[Total Earnings] as

Related

how to avoid the error "Category member XXX defined as an empty set" in icCube?

I've got the following MDX code to create a category dimension with 4 members:
all members that make up of 0-50% of the measure (TopPercent)
members 50-80%
members 80-95%
members 95-100%
The code works perfectly on levels with a lot of members:
WITH
MEMBER [measures].[v] as eval([Tijd].[Tijd].[jaar].[2018],[Measures].[Bedrag])
set [selection] as Order( nonempty([Categorie].[Categorie].[categorie].members,[measures].[v]), [measures].[v], BDESC)
CATEGORY HIERARCHY [Stats].[ABCD], DEFAULT_MEMBER_NAME = "Totaal", LEVEL_NAME_PATTERN="L - ABCD - ${levelDepth}"
CATEGORY MEMBER [Stats].[ABCD].[Totaal].[A (0-50%)] as
TopPercent([selection],50, [measures].[v] ), ADD_CHILDREN=true
CATEGORY MEMBER [Stats].[ABCD].[Totaal].[B (50-80%)] as
TopPercent([selection],80, [measures].[v] )
- TopPercent([selection],50, [measures].[v]), ADD_CHILDREN=true
CATEGORY MEMBER [Stats].[ABCD].[Totaal].[C (80-95%)] as
TopPercent([selection],95, [measures].[v])
- TopPercent([selection],80, [measures].[v] ), ADD_CHILDREN=true
CATEGORY MEMBER [Stats].[ABCD].[Totaal].[D (95-100%)] as
Order([selection], [measures].[v], BDESC)
- TopPercent([selection],95, [measures].[v]), ADD_CHILDREN=true
SELECT
// Measures
{[measures].[v]} On 0,
// Columns
[Stats].[ABCD].[L - ABCD - 1].members on 1,
// Rows
[Stats].[ABCD].[L - ABCD - 2].members on 2
FROM (select [Tijd].[jaar].[2018] on 0 from [Spendzoom])
/*ic3navigation*/
But when I run the MDX code with:
set [selection] as Order( nonempty([Categorie].[Categorie].[type].members,[measures].[v]), [measures].[v], BDESC)
I get the error: Category member "[Stats].[ABCD].[Totaal].[C (80-95%)]'defined as an empty set.
I have tried to rewrite the definitions, as:
subcubeminus(TopPercent .... , TopPercent)
But that gave completely strange results.
How can I overcome this error and have a generic approach that allways works regardless of the contents of the hierarchy & level in the [selection] definition?
To understand what happening you should check how TopPercent works (it's not really whay you expected).
Try this MDX :
WITH
MEMBER [measures].[v] as eval([Tijd].[Tijd].[jaar].[2018],[Measures].[Bedrag])
STATIC SET [selection] as [Categorie].[Categorie].[categorie].members
SELECT
[measures].[v] On 0,
TopPercent([selection],95, [measures].[v]) on 1,
TopPercent([selection],80, [measures].[v] ) on 2
FROM
(select [Tijd].[jaar].[2018] on 0 from [Spendzoom])
As you see both return the same set, and that is not what you are looking I guess.
As ic3 mentioned in the comments, as of icCube 6.8.10, icCube allows now to have empty categories. Y
For me this means, business wise, that regardless of the global filter settings the categories ALWAYS work. In case it is an empty set, it results a blank value in the dashboards.
example of a Parato analysis for just 1 vendor (bedrag = amount, #Fact = nr of invoices, #Lev = nr of suppliers)
Exactly as desired.

SSAS: How can I create calculated member using multiple conditions on different hierarchy

I have problem with my SSAS Cube.
I have to implement basic calculation to my Cube:
sum(Ammount) where BOOK = "Assets" and CD_PRODUCT_L4 <> "LoanLoss"
My dimmension is in image below:
Dimension attributes: BOOK, CD_PRODUCT_L4, CD_PRODUCT_L5, ..
Hierarchy PROD: CD_PRODUCT_L4 - CD_PRODUCT_L5
CREATE MEMBER CURRENTCUBE.[Measures].[Principal Loans]
AS (
except(
[PLV PRH HDIM CB].[BOOK].&[ASSETS_ON],
[PLV PRH HDIM CB].[COD PRODUCT L4].&[51L4]
),
[Measures].[EOM PRINCIPAL_a])
The biggest thing is that conditions are not from same hierarchy level so I can't use except and I know no other way to implement this particular condition set
Please HELP, Thank you
Product dimmension model
I manage to solve the issue by adding hierarchy to my dimension which allowed me to use except as I wanted before but I'am not satisfied with this solution because it looks more like workaround then solution
CREATE MEMBER CURRENTCUBE.[Measures].[Principal Loans] AS
sum((except([PLV PRH HDIM CB].[Hierarchy BOOK].[BOOK].&[ASSETS_ON].children,[PLV PRH HDIM CB].[Hierarchy BOOK].[COD PRODUCT L4].&[51L4]),[Measures].[EOM PRINCIPAL_a]))
This is probably the closest example that I can provide you to what you need.
This, code below, is just one of about 50 or so Measures we have defined, ranging from Counts, Averages, Sums, Percentages, etc. We take a single DW value and perform at least 2 seperation calculations, most have 4 or more different calculations, from that one field.
CREATE MEMBER CURRENTCUBE.[Measures].[Count Previous Difference]
AS Case
// Test for current coordinate being on (All) member.
When [Date].[YearMonth].CurrentMember.Level Is [Date].[YearMonth].[(All)]
Then "NA"
Else
( [Date].[YearMonth].CurrentMember, [Measures].[Gross Count] )
-
( ParallelPeriod (
[Date].[YearMonth].CurrentMember.Level,
1,
[Date].[YearMonth].CurrentMember
),
[Measures].[Gross Count]
)
End,
FORMAT_STRING = "#,##0.00;-#,##0.00",
NON_EMPTY_BEHAVIOR = { [Gross Count] },
VISIBLE = 0 , ASSOCIATED_MEASURE_GROUP = 'Some Summary';
Keep in mind we also use our DW & Cube with SharePoint and SSRS reports.

UNION multiple MDX queries in SSAS (powerpivot)

I have some sort of difficulties trying to join 2 MDX queries together. When running them separately they work fine. The script below
WITH
MEMBER [Measures].[ParameterCaption] AS
[Main_Incidents].[Priority].CurrentMember.Member_Caption
MEMBER [Measures].[ParameterValue] AS
[Main_Incidents].[Priority].CurrentMember.UniqueName
MEMBER [Measures].[ParameterLevel] AS
[Main_Incidents].[Priority].CurrentMember.Level.Ordinal
SELECT
{
[Measures].[ParameterCaption]
,[Measures].[# Incidents]
,[Measures].[%SLA]
} ON COLUMNS
,[Main_Incidents].[Priority].ALLMEMBERS ON ROWS
FROM [Model];
WITH
MEMBER [Measures].[ParameterCaption] AS
[Main_Incidents].[usr_directorate].CurrentMember.Member_Caption
MEMBER [Measures].[ParameterValue] AS
[Main_Incidents].[usr_directorate].CurrentMember.UniqueName
MEMBER [Measures].[ParameterLevel] AS
[Main_Incidents].[usr_directorate].CurrentMember.Level.Ordinal
SELECT
{
[Measures].[ParameterCaption]
,[Measures].[# Incidents]
,[Measures].[%SLA]
} ON COLUMNS
,[Main_Incidents].[usr_directorate].ALLMEMBERS ON ROWS
FROM [Model];
The most important bit for me is that I need the label column to show. So I want to UNION the 2 queries together so that the ParameterCaption captures values from "Priority" dimension and "Directorate" dimension....
Please someone help me to achieve this?
This is a bit complex, but definitely possible.
Union in MDX only works for members of the same hierarchy, so to achieve this we need to make the row members into Tuples that combine the two hierarchies. We can do this by cross joining each of the ALLMEMBERS sets to the [All] member for the other hierarchy. Then we just need to change the Parameter Caption, Value and Level to conditionally get the value from the appropriate hierarchy.
This could look something like the code below:
WITH
MEMBER [Measures].[ParameterCaption] AS
IIF([Main_Incidents].[Priority].CurrentMember.Level.Ordinal = 0, [Main_Incidents].[usr_directorate].CurrentMember.Member_Caption, [Main_Incidents].[Priority].CurrentMember.Member_Caption)
MEMBER [Measures].[ParameterValue] AS
IIF([Main_Incidents].[Priority].CurrentMember.Level.Ordinal = 0, [Main_Incidents].[usr_directorate].CurrentMember.UniqueName, [Main_Incidents].[Priority].CurrentMember.UniqueName)
MEMBER [Measures].[ParameterLevel] AS
IIF([Main_Incidents].[Priority].CurrentMember.Level.Ordinal = 0, [Main_Incidents].[usr_directorate].CurrentMember.Level.Ordinal , [Main_Incidents].[Priority].CurrentMember.Level.Ordinal)
SELECT
{
[Measures].[ParameterCaption]
,[Measures].[# Incidents]
,[Measures].[%SLA]
} ON COLUMNS
,{
[Main_Incidents].[Priority].ALLMEMBERS * [Main_Incidents].[usr_directorate].[All],
[Main_Incidents].[Priority].[All] * [Main_Incidents].[usr_directorate].ALLMEMBERS
} ON ROWS
FROM [Model];

MDX - icCube - How to get a DYNAMIC topcount/toppercent with other aggregated?

Using the following mdx, I'm able to retrieve correct data dynamically.
create CATEGORY MEMBER [Stats].[Top].[All Etabs].[Top 5 Etablissements]
as topcount( [Etablissement].[Etablissement].[Etablissement].allMEMBERS, 5, [Measures].[Nbsejours]),ADD_CHILDREN=true
create CATEGORY MEMBER [Stats].[Top].[All Etabs].[Autres Etablissements (>5)]
as Except([Etablissement].[Etablissement].[Etablissement].members, TopCount( [Etablissement].[Etablissement].[Etablissement].MEMBERS, 5, [Measures].[Nbsejours])),ADD_CHILDREN=false
create dynamic set [Top 5 & Others]
as {[Stats].[Top].[Top 5 Etablissements], [Stats].[Top].[Autres Etablissements (>5)]}
Select {[Measures].[NbSejours]} on 0,
nonempty ([Top 5 & Others]) on 1
From //[Cube]
( SELECT { {[Geographique].[Zone].[All-M].&[1006]} } ON 0 FROM [Cube])
But, the topCount is not dynamic itself. In this example, the top 5 etablissement never change, only the values do change...
Is there a way to get this with dynamic topCount/topPercent ?
Txs,
Bertrand.
Categories (*) have not yet the dynamic flag so it's not possible to define a category that will be calculated for each MDX request once as it happens for a set.
So it's going to be something more like (note I've use the SubCubeComplement that is a lot - may be really a lot - faster )
create dynamic set [Top 5] as
topcount( [Etablissement].[Etablissement].[Etablissement].members, 5, [Measures].[Nbsejours])
*** End script ***
WITH
CATEGORY HIERARCHY [Stats].[Top], DEFAULT_MEMBER_NAME = "All Etabs"
CATEGORY MEMBER [Stats].[Top].[All Etabs].[Top 5 Etablissements] as
[Top 5],ADD_CHILDREN=true
CATEGORY MEMBER [Stats].[Top].[All Etabs].[Autres Etablissements (>5)] as
SubCubeComplement([Top 5]),ADD_CHILDREN=false
SELECT
{[Measures].[NbSejours]} on 0,
{ [Stats].[Top].[Top 5 Etablissements],
[Stats].[Top].[Autres Etablissements (>5)] } on 1
From [Cube]
(*) For the people that are not used to icCube, Categories is a way defining a 'new' member as a set of members (they might have different dimensionalities). This ensures for complex calculations, schemas with many-to-many relations that the values are correctly calculated. Otherwise it might be a little nightmare to ensure calculation correctness.

How to get a COUNT of NON-NULL members in a set with some conditions?

To give you a slight background to the problem, there are certain "users" who do certain "tasks" which are categorized into various types; one such type being "DSR". The requirement I am faced with is to find how many requests of type DSR the userid 033343 worked on for each month of year 2013.
What I would be needing is to get the count of the members in set of all the distinct requests a user (Userid = 033343) worked on in the year = 2013 and for the Request Type = DSR.
Below is what I tried at first:
WITH SET requests AS
EXISTING [Request].[RequestID].MEMBERS
MEMBER Measures.[Count033343] AS
DISTINCTCOUNT(requests)
SELECT Measures.[Count033343] ON 1,
[Calendar].[CalendarMonthName].CHILDREN ON 0 /*Values like January, February, etc. Not tied to Calendar Years*/
FROM [Model]
WHERE(
[User].[UserID].&[033343],
[Request Type].[Request Type Name].&[DSR],
[Calendar].[CalendarYear].&[2013]
)
But that didn't work. I got below result.
I figured, there is an issue with the set that I was building.
Then I moving the MDX to the Set definition. I thought it might make the code work faster as compared to having an extra set of tuple in WHERE clause.
WITH SET requests AS
EXISTS([Request].[RequestID].MEMBERS, (
[User].[UserID].&[033343],
[Request Type].[Request Type Name].&[DSR],
[Calendar].[CalendarYear].&[2013]
))
MEMBER Measures.[Count033343] AS
DISTINCTCOUNT(requests)
SELECT Measures.[Count033343] ON 1,
[Calendar].[CalendarMonthName].MEMBERS ON 0
FROM [Model]
But I was still getting the same result as above - 0 as the count for all the months!
Then, I thought of checking the set itself I was building(In the second example)
WITH SET requests AS
EXISTS([Request].[RequestId].MEMBERS, (
[User].[UserID].&[033343],
[Request Type].[Request Type Name].&[DSR],
[Calendar].[CalendarYear].&[2013]
))
SELECT [Measures].[Average of Late Tasks] ON 1,
requests ON 0
FROM [Model]
That proved two things.
1) The set was returning NULL values along with non null values.
2) There are indeed Request Ids returned from the set. So the count of Requests is definitely greater than 0 for the tuple specified.
I could use the NON EMPTY clause to remove the NON NULL values but, I don't want to use it as I read that it adds overhead.
As I have verified above that there are indeed requests for various users for all the months in 2013, why I am getting the count to be 0? Where am I going wrong? Why isn't the EXISTS and EXISTINGfunctionality working as expected? Isn't the set supposed to return only those Request IDs which exist for the condition? Is my understanding wrong?
EDIT
For #whytheq - With your final query, I got non-zero values
WITH MEMBER Measures.[x] AS
Count(
NONEMPTY(
[Request].[RequestId].MEMBERS
, {([Measures].[Average of Late Tasks])}
)
)
SELECT
Measures.[x] ON 0,
[Calendar].[CalendarYear].&[2013] ON 1
FROM [Model]
OUTPUT
x
2013 2
(Not tested) Does this still return zeros?
WITH SET [requests] AS
{([User].[UserID].&[033343],
[Request Type].[Request Type Name].&[DSR])}
* {[Measures].[Average of Late Tasks]} //<<<<try running with and without this line
* [Request].[RequestID].MEMBERS
MEMBER Measures.[Count033343] AS
DISTINCTCOUNT(requests)
SELECT
[Calendar].[CalendarMonthName].CHILDREN ON 0,
Measures.[Count033343] ON 1
FROM [Model]
WHERE(
[Calendar].[CalendarYear].&[2013]
)
How about the following?
WITH
MEMBER Measures.[Count033343] AS
DISTINCTCOUNT({[Request].[RequestID].[RequestID]})
SELECT
[Calendar].[CalendarMonthName].CHILDREN ON 0,
Measures.[Count033343] ON 1
FROM [Model]
WHERE(
[Calendar].[CalendarYear].&[2013],
[User].[UserID].&[033343],
[Request Type].[Request Type Name].&[DSR]
)
Maybe try this simpler query first and (if it works!) we can build up from this to try to locate the problem...
WITH MEMBER Measures.[x] AS
Count(
NONEMPTY(
[Request].[RequestId].MEMBERS
, {([Measures].[Average of Late Tasks])}
)
)
SELECT
Measures.[x] ON 0,
[Calendar].[CalendarYear].&[2013] ON 1
FROM [Model]