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.
Related
I need to write a script in my SSAS project (cube calculation) that calculate Opening and closing stock value on specific date.
In this screen short first table showing my raw data and second table is showing my required BI values .
Opening stk (stock) on 2015-02-01 product A was 18 and that day price was 10 so 10*18 = 180 stk value,
on 2015-02-08 price was 9 for same product and closing stk was 10 (so 9*10=90) is a closing stock value.
I have use below code for this but this script is not showing required results.
Scope([Measures].[Closing Stock]);
This = sum((
null:[Time].[Year].CurrentMember *
null:[Time].[Quarter].CurrentMember *
null:[Time].[Month Name].CurrentMember *
null:[Time].[Month].CurrentMember *
null:[Time].[date].CurrentMember )
,[Measures].[Movement Qty]) * Price;
FORMAT_STRING ( This ) = "#,#";
End Scope;
For what I understand you want to display the remaining stock and the remaining stock value for each day. The script below will work only at day levels. I am have assumed that you have the following measurse in your cube [Meausres].[Opening],[Measures].[Qty],[Measures].[Price] and you have [date] dimension and a level named [date] in this dimension
with
member measure.ClosingCount
as
sum([date].[date].currentmember, [Meausres].[Opening]-[Measures].[Qty])
member measure.ClosingAmount
as
sum([date].[date].currentmember, [measure].[ClosingCount]*[Measures].[Price] )
Edit based on the comment
with
member measure.ClosingCount
as
sum(([date].[date].currentmember,[Product].[Product].currentmember), [Meausres].[Opening]-[Measures].[Qty])
member measure.ClosingAmount
as
sum(([date].[date].currentmember,[Product].[Product].currentmember), [measure].[ClosingCount]*[Measures].[Price] )
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' ;
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.
I want to calculate percentage of individual Categories, Here is my mdx code.
WITH
MEMBER [Measures].[Individual_Total] AS ([DIM RATING STRINGS].[LABEL]*[Measures].AGG_RATING Count])
SELECT
NONEMPTY {
[Measures].[AGG_RATING Count],[Measures].[Individual_Total]
} ONColumns,
([DIM STRUCTURE].[PARENT CODE].&[M01]&[M]:[DIM STRUCTURE].[PARENT CODE].&[M11]&[M],
[DIM TAILORING].[TAILORING_LABEL].[TAILORING_LABEL],
{[DIM RATING STRINGS].[LABEL].[LABEL],[DIM RATING STRINGS].[LABEL]}
) onrows
FROM [Cube]
Here is the output
In this output we have 4 categories like ""External Drivers ,stretegy,Business operation and governance.
I need to calculate percentage of different color with in the same category.
For example if we take "External Drivers" then Calculation should be like
amber = 15/28 * 100, green = 5/28/*100 etc because 28 is the sum of external drivers.
Please tell me how to do this thing in mdx.
thanks
Here you can compare with my solution, it will give you the percent of the parent.
with
member [Measures].[Percent of parent] as
([Measures].[Order Quantity]) /
([Product].[Product Categories].currentmember.parent,
[Measures].[Order Quantity])
,format_string = "percent"
SELECT
{([Measures].[Order Quantity]),
([Measures].[Percent of parent])} ON COLUMNS,
{[Product].[Product Categories].[Category].&[3]} *
{[Product].[Subcategory].[Subcategory].Members} *
{[Product].[Style].[Style].Members} *
{[Product].[Product].members}
ON ROWS
FROM [Cube]
I don´t know if i read your dimensions correctly but maybe your member should look something like:
with member [Measures].[Percent] as
[Measures].[AGG_RATING Count] /
([DIM RATING STRINGS].[LABEL].CURRENTMEMBER.PARENT,
[Measures].[AGG_RATING Count])
, format_string = "percent"
I have created an MDX query which calculates the TOP 10 ZipCodes (according to my Patient Stay measure) as such:
WITH
MEMBER [Discharge Date].[Y-M-D].[ Aggregation] AS 'AGGREGATE( EXISTING { [Current Month] } )', SOLVE_ORDER = 0
SELECT
NON EMPTY { [Measures].[Patient Stays] }
ON COLUMNS,
TOPCOUNT({ ORDER( HIERARCHIZE( { [Patient].[ByZipcode].[All].CHILDREN } ), ( [Measures].[Patient Stays] ), BDESC ) }, 10)
ON ROWS
FROM [Patient Stay]
WHERE ( [Discharge Date].[Y-M-D].[ Aggregation], [Facility].[ByAffiliation].CURRENTMEMBER, [Facility].[ByRegion].CURRENTMEMBER )
This query is used to populate a PerformancePoint 100% Stacked Bar chart. The client has asked that since this is a !00% based chart, we lump the rest of the zip codes into an "Other" field, such that there should be 11 values: one for each of the top 10, and an eleventh which is a sum of the remaining Zip Codes.
I am an extreme novice to MDX, but this doesn't souund like it should be impossible. Does anyone have any ideas or suggestions?
I'll do my best with untested code, so here goes:
WITH
MEMBER [Discharge Date].[Y-M-D].[ Aggregation] AS 'AGGREGATE( EXISTING { [Current Month] } )', SOLVE_ORDER = 0
SET [Top10ZipCodes] AS
(TOPCOUNT({ ORDER( HIERARCHIZE( { [Patient].[ByZipcode].[All].CHILDREN } ), ( [Measures].[Patient Stays] ), BDESC ) }, 10))
MEMBER [Patient].[ByZipCode].[OtherZipCodes] AS
(AGGREGATE({EXCEPT([Patient].[ByZipCode].Members, [Patient].[ByZipCode].[Top10ZipCodes])}))
SELECT
NON EMPTY { [Measures].[Patient Stays] }
ON COLUMNS,
{[Top10ZipCodes], [Patient].[ByZipCode].[OtherZipCodes]}
ON ROWS
FROM [Patient Stay]
WHERE ( [Discharge Date].[Y-M-D].[ Aggregation], [Facility].[ByAffiliation].CURRENTMEMBER, [Facility].[ByRegion].CURRENTMEMBER )
What this does is creates a set of your top 10 ZIP codes, and then aggregates (different than sum!!!) all the ZIP codes, with the exception of your top 10.
Also, if this is a common set (top 10 ZIP codes), you may want to make a set on the cube, where you can reuse it ad nauseum, without having to change every MDX query you have.
Cheers,
Eric