Switch for different Measures - mdx

I would like to use three currencies for the reporting. These currencies come as columns in the facts. So we have 3 meausures
[Measures].[Amount EUR]
[Measures].[Amount USD]
[Measures].[Amount CHY]
for the Amount in EUR, USD, CHY.
The user can select his currency preferably in the global filter menu. Therefore, we use an additional Dimension [Currency Reporting] which contains the three currencies EUR, USD, CHY, which is not mapped to the Cube.
Depending on the selection, the different measures should be used in all the MDX statements of all widgets.
Currently, we use the function currencyCheck to check which element of the currency dimension was selected, and it accordingly chooses the measure.
Is there a standard way of doing this? Do you have any experience with this, and an idea of the best practise way to do it?
iif
(Curr_Member is [Currency Reporting].[Currency Reporting].[Currency Reporting].[EUR],
[Measures].[Amount EUR],
iif(Curr_Member is [Currency Reporting].[Currency Reporting].[Currency Reporting].[USD],
[Measures].[Amount USD],
[Measures].[Amount CHY])
)
CREATE CALCULATED MEMBER [Measures].[Amount] as
currencyCheck([Currency Reporting].[Currency Reporting].CurrentMember )

It is an option if you have a few measures that are amounts (need fx).
If no another option is using a 'Utility/Statistical dimension' for doing fx calculations. You can inspire yourself from.
Note, if fx rates are time dependent you'll have to apply the fx for each month / day. Here it's not the case as you've the amounts already calculated for the different currencies

Related

How to get measure value for certain date range in MDX?

I am new to MDX and for now it looks like some hell to me.
I have a measure called Sales KG. It calculate sales amount based on table AData where I have column named Data_Date.
I need to get Sales KG value for specified range of dates.
The problem is I can't understand how to specify that range. It doesn't look like simple < and > are works here.
I totally lost and don't have much to show, but this is what I tried:
select
[Sales KG] on Columns
from [Model]
where ([Format_TT].[Супермаркет], [Data_Date].&[20160101] : [Data_Date].&[20170101])
But it tells me that can't convert string "20160101" into date type. And probably this is not what I want. I want it to be single value for date range in single cell.
What to do?..
Take a look at the below sample they will help .
Please note that "Date" is a dimesnion in the cube, which has an attribute "[Date]" in it. "[Measures].[Internet Sales Amount]" in the cube. It is necessary to have them defined in the SSAS project, If one of them is not defined in the project but exists in the base tables of star schema it will not work. MDX can only see objects defined in the SSAS project
//First way
select
[Measures].[Internet Sales Amount]
on columns
from [Adventure Works]
where {[Date].[Date].&[20130101]:[Date].[Date].&[20130131]}
Second way
select
[Measures].[Internet Sales Amount]
on columns,
{[Date].[Date].&[20130101]:[Date].[Date].&[20130131]}
on rows
from [Adventure Works]

Convert MDX calculated measure, to scope in SSAS calculations

I have got a measure, getting the last value of a currency exchange rate. The fact having the exchange rates, is configured in the dimension usage with the time dimension, and is daily based. So, using MDX, I am successfully getting my converted measure in my currencies, by using a calculated measure:
with member [Measures].[Calculated Comp Money In] as
SUM([Dim Time].[Date Key].CurrentMember,
[Measures].[Comp Money In]/[Measures].[Last Currency Rate])
And then in the where clause, I would filter out what currency I am reporting figures on
[Dim Currency].[Currency Key].&[200]
However, what I don't like is that I have a [Measures].[Comp Money In], and a [Measures].[Comp Money In Calculated].... Can I use the SCOPE function in MDX, so that [Measures.[Comp Money In] is configured with the calculation above? I would then add this calculation in the calculations section of SSAS.
If you use the Enterprise edition of SSAS, you can use the measure expression property of your measure do currency conversion. This is not very well documented in the Analysis Services documentation, but works as follows: You use only one measure (i. e. either [Measures].[Calculated Comp Money In] or [Measures].[Comp Money In], and in the "Measure expression" property of this measure, enter the expression that you have in your question above:
[Measures].[Comp Money In] / [Measures].[Last Currency Rate]
Then the Analysis Services engine will take care of the rest for you. Note that this expression may only contain the measure on which you define it, times or divided by one other measure (normally he exchange rate) and nothing else.
If you do not have The Enterprise edition of Analysis Services, you can more or less copy your definition to a calculated member:
To be able to continue using the existing measure, possibly rename the measure [Measures].[Comp Money In] to [Measures].[_Comp Money In] (and make that measure invisible when you have checked that everything is fine). Then define a calculated member with the same name as the original measure:
create member CurrentCube.[Measures].[Comp Money In] as
SUM([Dim Time].[Date Key].CurrentMember,
[Measures].[_Comp Money In]/[Measures].[Last Currency Rate])
Better still, use SCOPE to calculate the measure, and avoid the aggregation for single days: Assuming the only common dimension between the measure group containing [Measures].[Comp Money In] and the measure group containing [Measures].[Last Currency Rate] is [Dim Time] and this has the key attribute [Dim Time].[Date Key], and your date hierarchy is named [Dim Time].[Date], you could just use
CREATE MEMBER CurrentCube.[Measures].[Comp Money In] as NULL;
SCOPE([Dim Time].[Date Key].[Date Key].members);
[Measures].[Comp Money In] =
[Measures].[_Comp Money In] / [Measures].[Last Currency Rate];
END SCOPE;
SCOPE([Dim Time].[Date].Members);
[Measures].[Comp Money In] =
Sum(EXISTING [Dim Time].[Date Key].[Date Key].members);
END SCOPE;

SSAS Calculated Member - how to do percent of total based on another measure

I am currently trying to create a calculated measure for an SSAS 2008 R2 cube. In a financial cube dealing with accounts receivable data, I have a "Gross Balance" measure, and a "Days Since DOS" measure. The "Days Since DOS" measure is invisible to the user because it is only used in combination with a couple others to gain an average.
I would like the new calculated measure to show the percent of the total gross balance that has a Days Since DOS value > 90.
For example, if the total gross balance were $1000, the total gross balance for records with days since DOS > 90 being $500, the Percent Over 90 Days calculated measure would show 50%.
Would it be possible to do this with my current setup, and if so, how would I go about writing the expression?
I found out that it is in fact possible.
First, create a new named calculation in the DSV using a case statement (for example, call it [Gross Bal Over 90]):
CASE
WHEN [Days Since DOS] > 90 THEN [Gross Balance]
ELSE 0
END
Then, the calculated measure would simply be:
Sum([Gross Bal Over 90])/Sum([Gross Balance])
You can then make [Gross Bal Over 90] invisible to the user, keeping a cleaner look.

SSAS - Count Time Dimension

I looked at this topic, Calculating the number of days in a time dimension node - with Grand Total, but can't seem to get it.
I have a Time Dimension; [Invoice Date].
I want to count the number of Work Days in that dimension for a specified time period. I'm new to MDX.
Here's what I have.
Count(
Descendants(
[Invoice Date].CurrentMember,
[Invoice Date].[Work Date].[Work Date]
)
)
I'm getting a cube error now.
An easy way to implement this reliably would be to create a physical measure "Day Count". To do this, create a new measure group on the Date dimension table, and define "Day Count" as the Count. On the dimension usage tab, make sure you set a relationship from this measure group to the Invoice Date cube dimension and not the other dimensions.

SSAS MDX Calculated Measure Over Time

I have a calculated measure that needs to cross join Customer and Product dimension then cross join a total sales measure to get a percentage for a specific customer sale.
[Measures].[Sale Value] / [Measures].[Total Sales]
each measure has a link to the time dimension, and are set to last non empty.
The problem is that as I look at more information over longer periods (days, months, years etc) it gets slower and slower and slower. I am assuming this is because the calculated measure does its processing on the fly and there is no caching.
Is this correct? I have about 2000 customers and 50 products.
Please please help! any information about how to speed this up would be great.
The answer to this was to set a many to many relationship between Customer/Prodcut and the [Measures].[Total Sales] measure group.