MDX Calculated member fixed - ssas

i want to ask, if there is some function in MDX language, which returns me a same value in any case..
I created a calculated member, that's indicate how much value was sold on last year. It's work fine. But if I in slicer or filter exclude year value of the last year, i get nothing. Is there any function, that calculate a value with no filter?
For example, I need function like calculate in DAX in power pivot.
Thanks
Edit:
MDX calculated member for [Mat value]:
CREATE MEMBER CURRENTCUBE.[Measures].[MAT value]
AS SUM([03 Datumy].[MAT].&[MAT],[Measures].[Sales value]),
FORMAT_STRING = "#,##0.00;-#,##0.00",
VISIBLE = 1 , DISPLAY_FOLDER = 'Sales value' , ASSOCIATED_MEASURE_GROUP = '04 Hodnoty' ;
MDX calculated member for [Mat-1 value]:
CREATE MEMBER CURRENTCUBE.[Measures].[MAT-1 value]
AS SUM([03 Datumy].[MAT].&[MAT-1],[Measures].[Sales value]),
FORMAT_STRING = "#,##0.00;-#,##0.00",
VISIBLE = 1 , DISPLAY_FOLDER = 'Sales value' , ASSOCIATED_MEASURE_GROUP = '04 Hodnoty' ;
mat2014 http://www.attanon.eu/mat2014.PNGmat2013 http://www.attanon.eu/mat2013.PNG
filters http://www.attanon.eu/filters.PNGall http://www.attanon.eu/allmat.PNG
Edit2:
MAT and MAT-1 is based on column with this value. I have dimension like this:
dimension http://www.attanon.eu/dimension.PNG
And data looks that:
datumy http://www.attanon.eu/datumy.PNG
Relationship in [03 Datumy]:
relations http://www.attanon.eu/relations.PNG
The mat is calculated in SQL server. Because, i don't have much time to calculate the hiearchy in cube.

(discussion updates were removed as lack of necessity)
UPDATE to fix an issue:
Since your calculation, that determines months belonging to certain month, based on SQL, you can filter-out Date hierarchy by rewriting MAT-measures with adding [03 Datumy].[Year].[All]:
CREATE MEMBER CURRENTCUBE.[Measures].[MAT value]
AS ([03 Datumy].[MAT].&[MAT],[03 Datumy].[Year].[All],[Measures].[Sales value]),
FORMAT_STRING = "#,##0.00;-#,##0.00",
VISIBLE = 1 , DISPLAY_FOLDER = 'Sales value' , ASSOCIATED_MEASURE_GROUP = '04 Hodnoty' ;
and the same for next one:
CREATE MEMBER CURRENTCUBE.[Measures].[MAT-1 value]
AS ([03 Datumy].[MAT].&[MAT-1],[03 Datumy].[Year].[All],[Measures].[Sales value]),
FORMAT_STRING = "#,##0.00;-#,##0.00",
VISIBLE = 1 , DISPLAY_FOLDER = 'Sales value' , ASSOCIATED_MEASURE_GROUP = '04 Hodnoty' ;
Actually, it's an equivalent of old SSAS-2000 function .Ignore.

Related

Dynamically measured measure (MDX)

good night!
I'm new to the MDX world and I'm having a hard time creating a calculated measure, the problem is this: I have a measure that is calculated using the final balance of the previous month as the balance of the current month. Something similar to what they see below.
This is how the data should appear
The problem is that the mdx script I did not add the previous data to the display and so it ends up showing me an incorrect initial value. In the image above it should return the final balance calculated from the beginning of the company to the selected filter. Can anyone help me?
This is how it is showing up.
Here is the mdx query I created:
with Member [Saldo Final 2] as
([Measures].[Certificados Novos] + [Measures].[Reativados] - [Measures].[Cancelados Menor ou Igual a 6 Parcela] - [Measures].[Cancelados Maior que a 6 Parcela])
member [Saldo Final Mês Anterior 2] as
(ParallelPeriod ([DIM TEMPO].[MES ANO].[MES ANO]
, 1
, [DIM TEMPO].[MES ANO].CurrentMember
), [Saldo Final 2])
member [Saldo Inicial 2] as
Sum([DIM TEMPO].[MES ANO].CurrentMember.FirstSibling:[DIM TEMPO].[MES ANO].CurrentMember, [Saldo Final Mês Anterior 2])
member [Final] as
[Saldo Inicial] + [Measures].[Saldo Final 2]
select [DIM TEMPO].[MES ANO].[MES ANO] on columns,
{[Measures].[Certificados Novos], [Measures].[Reativados], [Measures].[Cancelados Menor ou Igual a 6 Parcela],
[Measures].[Cancelados Maior que a 6 Parcela], [Final]
} on rows
from [dw_sinaf]
where
{[DIM TEMPO].[ANO].&[2016]}
Not sure it's exactly what are you looking for, but I was able to do it on a simplified model:
Two measures are available:
Sales Only Units
Return Only Units
We need to have a SUM for every Day (Month in your example) running month-by-month from the initial Date.
Code for FINAL and INICIAL is here:
with member [Final] as
([Date].[Year Qtr Month].[Date].&[20170501]
,[Measures].[Sales Only Units])
+
SUM([Date].[Year Qtr Month].[Date].&[20170501]
:[Date].[Year Qtr Month].CurrentMember
,[Measures].[Return Only Units])
member [Inicial] as
([Final]-[Measures].[Return Only Units])
select non empty [Date].[YQM].[Date].members on 0
,{[Inicial],[Measures].[Sales Only Units],[Measures].[Return Only Units],[Final]} on 1
from [My_Cube]
BLUE is initial value "from the beginning of the company"
RED values to use if required to use another initial date
GREEN required running value
[Sales Only Units] should be ideally hidden for every member, except initial date in order not to confuse business users.

Where Clause using another Dimension Value

I'm trying to create a Calculated Member in my cube with where clause but couldn't figure how to achieve the proper result.
I created a calculated member "Outlook" using the below code to display only Forecast values.
CREATE MEMBER CURRENTCUBE.[Measures].[Outlook]
AS SUM(([Source Profile].[Source Profile Hierarchy].CurrentMember,
[Source Profile].[Profile Level01].&[Outlook]),
[Measures].[USD Amount]),
FORMAT_STRING = "#,##0;(#,##0)",
VISIBLE = 1 , DISPLAY_FOLDER = 'USD' , ASSOCIATED_MEASURE_GROUP = 'CARS';
Cube Result
Now I would like to filter the results dynamically based on another hidden dimension "Current_Month". This dimension always has current financial period value and it's corresponding outlook profile
Year_Month Outlook_Profile
2015010 10 + 2
Expected result should be "Outlook" measure showing value based on Current_Month dimension, which is '10 + 2' and rest of them should be 0
Expected result
Just to explain the requirement in SQL terms, I would like to achieve the below in MDX
Where Fact.Source_Profile=Dimension.Source_Profile
instead of
Where Fact.Source_Profile='10 + 2'
I'm not sure how to achieve this in Where Clause or by another means. I could see examples of hard coding values, like year.&[2015] but haven't seen one using dynamic values.
I found a solution myself and thought of sharing the same. Used StrToMember function to pass hidden dimension's member as a variable here.
CREATE MEMBER CURRENTCUBE.[Measures].[Outlook]
AS (
Sum
(
(
[Source Profile].[Source Profile Hierarchy].CurrentMember,
strtomember("[Source Profile].[Source Name].&[" + [Outlook Profile].[Outlook Profile].&[1].Member_Caption + "]")
)
,[Measures].[USD Amount]
)
),
FORMAT_STRING = "#,##0;(#,##0)",
VISIBLE = 1 , DISPLAY_FOLDER = 'USD' , ASSOCIATED_MEASURE_GROUP = 'CARS' ;

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.

MTD Function not working with SCOPE

SCOPE ([Measures].[Net IMS Volume]);
( [Time].[Time Calculations].[MTD] )
= SUM(
MTD([Time].[Time Hierarchy 1].CURRENTMEMBER)
,[Time].[Time Calculations].[Current Time]
);
END SCOPE;
I was expecting my MTD to be displayed across the dates of the month. but the result is that I just get data at the Month Level.
When I do the same thing over at SSMS w/ the ff.:
WITH MEMBER [Time].[Time Calculations].MIKE2 AS
SUM
(
MTD([Time].[Time Hierarchy 1].CURRENTMEMBER)
,[Time].[Time Calculations].[Current Time]
)
SELECT
{
([Time].[Time Calculations].[MTD],[Measures].[Net IMS Volume])
,([Time].[Time Calculations].MIKE2,[Measures].[Net IMS Volume])
} ON 0
,[Time].[Time Hierarchy 1].[Date] ON 1
FROM [My Cube];
I get data at Date Level. I'm experiencing this on YTD function also.
Your time dimensions may not be typed correctly. Specific typing is required for the YTD and MTD to function as expected.
MSDN reference to YTD function: https://msdn.microsoft.com/en-us/library/ms146039.aspx
In the "remarks" section of the definition:
If a member expression is not specified, the default is the current
member of the first hierarchy with a level of type Years in the first
dimension of type Time in the measure group.
The Ytd function is a shortcut function for the PeriodsToDate function where the Type
property of the attribute hierarchy on which the level is based is set
to Years. That is, Ytd(Member_Expression) is equivalent to
PeriodsToDate(Year_Level_Expression,Member_Expression). Note that this
function will not work when the Type property is set to FiscalYears.
You could test if this is your problem by converting to the use of PeriodsToDate:
WITH MEMBER [Time].[Time Calculations].MIKE2 AS
SUM
(
PeriodsToDate(
[Time].[Time Hierarchy 1].[Month Level]
, [Time].[Time Hierarchy 1].CURRENTMEMBER
)
,[Time].[Time Calculations].[Current Time]
)
SELECT
{
([Time].[Time Calculations].[MTD],[Measures].[Net IMS Volume])
,([Time].[Time Calculations].MIKE2,[Measures].[Net IMS Volume])
} ON 0
,[Time].[Time Hierarchy 1].[Date] ON 1
FROM [My Cube];

WHERE clause in calculated member

I am facing some problem to calculate values from comparing dimension's value. I have 3 dimensions (Datatype, Customer, Product) and one measure (GrossSales).
What would be the MDX query if I want GrossSales for ProductID = 1,2,3 and Dataype = 4,5,6?
Here Datatype has relationship with GrossSales, Customer has relationship with GrossSales and Product has relationship with Customer.
I am trying this but doesn't work
CREATE MEMBER CURRENTCUBE.[Measures].Forecast_Gross_Sales AS
(
SELECT NON Empty [Measures].[Gross Sale]
FROM [Measures]
WHERE (
[Data Type].[ID].[ID] = 4
AND [Chain].[Customer ID] = [Measures].[Customer ID]
)
), VISIBLE = 1
, DISPLAY_FOLDER = 'Forecast'
, ASSOCIATED_MEASURE_GROUP = 'Data Types';
It looks like you are just getting started with MDX. There are some fundamental concepts that will help you get what you need. This comparison of SQL and MDX might be helpful. MDX uses the where clause as a slicer (to select certain dimension members) rather than a filter. You can't put member = somevalue in the where clause. And you can't really use the where clause to define a relationship to some other table.
Instead, your where clause would be something more like
[Data Type].[ID].[ID].&[4]
Since I can't see your data model, I can't be sure, but I would guess that [Chain].[Customer ID] = [Measures].[Customer ID] is something that you want to define the the dimension usage of your cube rather than in the query.
Edit: Now that the question has been edited, it looks like you are creating a calculated member. in this case there is no select or where clause. It will look more like this:
CREATE MEMBER CURRENTCUBE.[Measures].Forecast_Gross_Sales AS
Aggregate([Data Type].[ID].[ID].&[4], [Measures].[Gross Sale])
, VISIBLE = 1
, DISPLAY_FOLDER = 'Forecast'
, ASSOCIATED_MEASURE_GROUP = 'Data Types';
The relationship from the measure group through the Customer dimension to the Chain dimension is something that should be defined in the dimension usage. This is called a Reference dimension relationship.