MDX multi-currency field involving All member - ssas

I am interested in getting some help regarding my mdx queries.
I wanted to have a field that is multi-currency. I was able to allow the user to aggregate if the currency was same.
SCOPE [Measures].[Base Gross Amount];
This =
iif([Measures].[Measures].[MaximumCurrencyID] = [Measures].[Measures].[MinimumCurrency ID], [Measures].[Base Gross Amount], "Multiple Currencies");
End Scope;
However, now the user also wants to display the appropriate currency format. So when I added another scope statement to format the measure, this works for the leaves but not for the All member, it just adds the word "All" to the formatting, any thoughts how can I get the descendants?
SCOPE ([Company Organization].[Order Company ID].members, [Measures].[Base Gross Amount] );
Format_String(this) = [Company Organization].[Symbol].currentmember.Member_Value + "#,#.##";
End Scope;

The problem must be originating here: [Company Organization].[Symbol].
Can you set the [Symbol] hierarchy so it has no All member: in a similar way that the measures hierarchy has no All member.

Related

how to have Member name instead of his key in MDX statements SSAS

There's an issue facing me. I am working on SSAS 2017 and I have dimensions used by 3 cubes. In one of my cube When I drag and drop my dimension member instead of getting the literal name of dimension member ([xxxx].[yyyy].[aaaa]) I got number [xxxx].[yyyy].&[1] ..
Please someone can tell me how to avoid this kind of behavior ?
To be more precise when i drag and drop in my mdx statement :
I have :
[Dim Sales Territory].[Sales Territory].[1] , [Dim Sales Territory].[Sales Territory].[2]
I want to get :
[Dim Sales Territory].[Sales Territory].[Canada] , [Dim Sales Territory].[Sales Territory].[Australia]
The [Dim Sales Territory] has key column [Sales Territory Id]
Thank you
If you change the MemberNamesUnique property to true on the Sales Territory attribute in the Dim Sales Territory dimension editor and redeploy you’re cube then the drag and drop member unique name reference should change.
But my question is why you want to do this? Do you just want the code to be more readable? Are the names unique?
By the way, you will want to edit your question to put an & on member unique names which reference by key ([Dim Sales Territory].[Sales Territory].&[1]). If you omit these & then you reference the name property of an attribute. If truly you aren’t getting an & then the problem is that you have used the wrong column as the name column and have already set MemberNamesUnique=true.

MDX Scope to get denominator

I have a SSAS multidimensional cube and i am trying to calculate a denominator for a query by using a scope statement.
I am trying to assign the measure "Total SalesCumulative" the total value of all the sales for all the stores. I want this to stay being the total value and not get sliced when in a pivot table. The measure called Total Sales sums up all the sales for each store. I have gotten as far as the below but this just returns the value for each store and shows the same value as Total Sales.
SCOPE ([Measures].[Total SalesCumulative],[Dim Store].[Store Name].members);
THIS = ([Dim Store].[Store Name].[All],[Measures].[Total Sales]);
END SCOPE;
Has anyone got any suggestions how I can amend this?
I have checked your formula on Adventure Works database, and it seems correct. Just to be sure, you can check what you get with the query like the one below in SSMS (without making scope assignment):
with member measures.[All Order Count] as
([Measures].[Internet Order Count],[Product].[Model Name].[All Products] )
select {[Measures].[Internet Order Count] ,measures.[All Order Count] } on 0,
[Product].[Model Name].members on 1
from [Adventure Works]
Have you tried to clear cash before running the query after you made the change?
Secondly, maybe there is some other scope assignment in the script, that affects the same measure and dimension and overrides your formula, because the last scope assignment wins.
Try to add FREEZE(THIS) to your scope statement just to check if it will change the numbers:
SCOPE ([Measures].[Internet Order Count],[Product].[Model Name].members);
THIS = ([Product].[Model Name].[All Products] , [Measures].[Internet Order Count]) ;
FREEZE(THIS);
END SCOPE;

How do I reuse a created member throughout an MDX statement?

I have a bunch of calculated members that I need to create which are referenced off a single date.
Rather than repeating the MDX that gets the date member for which the measure will be based off, is there a way to create the date member at the start, and then reference it throughout so that I don't have to repeat the MDX multiple times? I was thinking something like the below however it returns a NULL:
WITH MEMBER [Date].[Retail].[Closing Date] AS
IIF (
[Date].[Retail].CurrentMember.Level.Name = 'Date',
[Date].[Retail].CurrentMember.PrevMember,
[Date].[Retail].CurrentMember
)
MEMBER [Measures].[Closing New] AS
(
[Date].[Retail].[Closing Date],
[Measures].[On Hand Quantity]
)
SELECT
[Date].[Retail].[Date].Members ON ROWS,
{
[Measures].[On Hand Quantity],
[Measures].[Closing New]
} ON COLUMNS
FROM
Retail
WHERE
[Date].[Retail Year].&[2017]
As above, I want to use the Closing Date member multiple times for various calculations.
To investigate why it is returning null try something like the following to see if it is as you expect:
WITH
MEMBER [Measures].[nm] AS
[Date].[Retail].CurrentMember.Level.Name
SELECT
{
[Measures].[On Hand Quantity],
[Measures].[nm]
} ON 0,
[Date].[Retail].[Date].Members ON 1
FROM Retail
WHERE [Date].[Retail Year].&[2017];
(I also switched the declaration order inside the SELECT clause as it is standard to declare columns, as it is axis 0, first followed by rows)
Why yes, there is!
the pattern I follow here is to create a set of one member then reference the first item of that set.
with set currentDate as
[Date].[Retail].[Date].&[20160725]
then reference it in the remainder of your query as
currentDate.item(0)

Alias MDX Query SSAS

WITH MEMBER [Measures].[NetPromoterScore] AS (IIF(([Measures].[Net Promoter Score] = 1/0 OR
[Measures].[Net Promoter Score] = -1/0 OR ISEMPTY([Measures].[Net Promoter Score])
OR [Measures].[Avg Revenue Per Unit] = 1/0 OR [Measures].[Avg Revenue Per Unit] = -1/0 OR
ISEMPTY([Measures].[Avg Revenue Per Unit]) ), NULL, [Measures].[Net Promoter Score]))
MEMBER [Measures].[AvgRevenuePerUnit] AS (IIF(([Measures].[Net Promoter Score] = 1/0
OR [Measures].[Net Promoter Score] = -1/0 OR ISEMPTY([Measures].[Net Promoter Score])
OR [Measures].[Avg Revenue Per Unit] = 1/0 OR [Measures].[Avg Revenue Per Unit] = -1/0
OR ISEMPTY([Measures].[Avg Revenue Per Unit]) ), NULL, [Measures].[Avg Revenue Per Unit]))
SELECT NON EMPTY
{ {[Measures].[NetPromoterScore],[Measures].[AvgRevenuePerUnit]} }
ON COLUMNS ,
NON EMPTY
{{Hierarchize(DrilldownLevel({[Roles].[Enterprise Role].[ALL]}))}}
DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME
ON ROWS
from Enterprise
WHERE (FILTER( [Employees].[EID].[EID],[Measures].[Avg Revenue Per Unit]> 700),
{[Areas].[Area].&[3]},
{[Markets].[Market].&[1]},{[Regions].[Region].&[2]},{[Locations].[Location].&[6],[Locations].[Location].&[6]},
{[Dates].[Date].&[20130219]:[Dates].[Date].&[20130318]})
As you see I have aliased [Net Promoter Score] column name with [NetPromoterScore] and [Avg Revenue Per Unit] column name with [AvgRevenuePerUnit]. But in my C# code, the names used are [Net Promoter Score] and [Avg Revenue Per Unit] and I can't change these previous name with new aliased name because I have to make changes in dozens of files and then I have to test whole application. Can I alias twice in the query above to get same previous column names or can I without aliasing get the same result from the query above?
Actually, in the sense of MDX, you have not aliased the members, but created new members.
I see two possibilities how you can solve this:
Move these calculations to the cube calculation script, i. e. rename
the original measures in the cube, and define calculated measures
with the name that you need and the same calculation that you have
in your query. You would then make the original renamed measures
invisible. This would be the best solution in my eyes, as it would
let every cube user benefit from the improvement, without breaking
external code or queries.
Depending on how exactly you reference the measures in your C# code
(you did not post samples), you could just use the caption property
of the measures, i. e. re-write the member definitions as follows:
WITH MEMBER [Measures].[NetPromoterScore] AS IIF(...), CAPTION = 'Net Promoter Score'
MEMBER [Measures].[AvgRevenuePerUnit] AS IIF(...), CAPTION = 'Avg Revenue Per Unit'

SSAS: Percent of Total not working in hierarchy

I have a simple olap cube - one set of measures and some unexciting dimensions.
I've add one calculation to get the "percent of total" sales against the gross sales measure. The code for this calculation is:
([Dim Stores].[Store Name].CurrentMember, [Measures].[Gross Sales])
/
([Dim Stores].[Store Name].Parent, [Measures].[Gross Sales])
This works.
Within the store dimension, there is a hierarchy called 'By State' where the stores are contained within.
Two questions please:
1. Any idea why the calculation would not work when I use the the 'By state' hierarchy i.e. the same calculation grouped by the next level up?
The state problem aside, any idea why my grand total shows an error even when I just use the Store Name?
TIA!
In poking around, I found a template within the "calculation tools" called "Percentage of Total". Using it, I translated my calculation to this:
Case
// Test to avoid division by zero.
When IsEmpty
(
[Measures].[Gross Sales]
)
Then Null
Else ( [Dim Stores].[By State].CurrentMember, [Measures].[Gross Sales] )
/
(
// The Root function returns the (All) value for the target dimension.
Root
(
[Dim Stores]
),
[Measures].[Gross Sales]
)
End
It worked!