MDX, calculated member with olap cube - mdx

I have a question related to cubes with Microsoft Technologies, we have an SSAS Cube built on BIDS 2008 version, and the requirement is to group (sum) the measure quantity taking the previous twelve months and excluding some values in one dimension.
I have come up with a calculation inside the cube as follows:
CREATE MEMBER CURRENTCUBE.[Measures].[N-12]
AS Sum
(
(
Except
(
[Dim Sistema Corporativo].[Sistema Corporativo].[Id Sistema]
,{
[Dim Sistema Corporativo].[Sistema Corporativo].[Id Sistema].&[3]
,[Dim Sistema Corporativo].[Sistema Corporativo].[Id Sistema].&[4]
}
)
,lastperiods(12,
[Dim Tiempo].[Fecha].CURRENTMEMBER
)
)
,
[Measures].[importe]
)/*Lime*/,
VISIBLE = 1 ;
I get something like this:
Row Importe N-12
2011 12399121166 12399121166
01.2011 1040785565 1040785565
02.2011 1069453202 2110238768
03.2011 1359303502 3469542269
04.2011 1068266294 4537808563
05.2011 1163538168 5701346731
06.2011 1146393010 6847739741
07.2011 936369144.8 7784108886
08.2011 1000363518 8784472404
09.2011 859885351.7 9644357755
10.2011 779035206.2 10423392962
11.2011 933409920.9 11356802882
12.2011 1042318283 12399121166
2012 25162093544 22225879797
01.2012 -40878580.57 11317457020
02.2012 678706164.3 10926709982
03.2012 16323643149 10555714716
04.2012 947692878 10435141301
05.2012 1057496411 10329099544
06.2012 1103249990 10285956525
07.2012 976810086.3 10326397466
08.2012 1046738046 10372771994
09.2012 1027644991 10540531634
10.2012 1108157924 10869654352
11.2012 932832484 10869076915
12.2012 9826758631
2013 22225879797
2014 22225879797
2015 22225879797
2016 22225879797
2017 22225879797
2018 22225879797
2019 22225879797
2020 22225879797
2021 22225879797
2022 22225879797
2023 9826758631
As you can see it is doing the right thing altough the user asked me to make some tweaks:
First one is that the cube does not show anything if theres no data (identified as "importe" measure group) and as you can see it shows blank spaces for the next years (until 2023) when when there's no data for the default measure group.
Second one is that the user only wants to see data if and only if the current member has 12 previous months so for example, right now is showing info for the year 2011 but as the user said it should only display data for the year 2012 because all those months have previos 12 months and 2011 does not have 2010 data so for this I should have a null value.
is it possible to do this...???
or maybe you can suggest any other option like affecting the fact table directly and so on.
Thank you in advise guys.

To check if the current member has 12 previous month you can use an expression like this one:
IIf(Count(
NonEmpty(lastperiods(12, [Dim Tiempo].[Fecha].CURRENTMEMBER),
[Measures].[importe])
) = 12,
...,
...)

Related

Problem with calculated member in Schema Workbench

I have the Formula:
(([Measures]. [QuantityPathology])/([Measures]. [QuantityPersons],
[DimPathology.Pathologies].[All])) * 100
The numerator is the measure QuantityPathology and the denominator is the QuantityPeople grouped by the member All of the hierarchy Pathologies, that is the total number of people served in that period regardless of the selected pathology.
But it does not work, since saiku analysis does not display any results, which may be doing wrong.
Modify message
Attached is an example of the formula
(([Measures], [QuantityPathology])/([Measures], [QuantityPeople],
[DimPathology.Pathologies][All])) * 100
QuantityPathology with Bronchitis year 2019 = 61
Number of people served in the year 2019 = 4569
61/4569 = 0,013350843*100
Result =1,3350843
Also avg(NumberPeople) does not work in all rows returns 1
I don't have any error in catalina.out
Thank you very much.

Summing up variable by preset N observations

I am running into problems doing a fairly basic summation.
My dataset is composed of company ID's (cusip8) and their daily (date) abnormal returns (AR). I need to sum the abnormal returns of each company, from days t+3 until t+60 forward.
cusip8 year date ret vwretd AR
"00030710" 2014 19998 . .0007672172 . .
"00030710" 2014 19999 .008108087815344334 .009108214 -.0010001262 .
"00030710" 2014 20002 .03163539618253708 -.00158689 .033222288 .
"00030710" 2014 20003 0 -.014999760000000001 .01499976 .
"00030710" 2014 20004 -.005717287305742502 .0158898 -.02160709 .
"00030710" 2014 20005 .006272913888096809 -.02121511 .027488023 .
"00030710" 2014 20006 -.012987012974917889 -.01333873 .000351717 .
I have tried the following:
sort cusip8 date
by cusip8: gen CAR = AR if _n==1
(24,741,003 missing values generated)
by cusip8: replace CAR = AR +CAR[_n-1] if _n>3 & if _n<60
And have yet been left with just .'s in the newly generated variable. Does anyone know how to solve this?
I am using Stata 16.0.
You have more problems than one. First, let's address your problem report.
In each panel, CAR[2] is created missing by your code, which creates CAR only in the first observation. That messes up all subsequent calculations, as for example CAR[3] is AR[3] + CAR[2], and so missing, CAR[4] is AR[4] + CAR[3] and so missing, and so on.
Contrary to your claim, in each panel CAR[1] should be non-missing whenever AR is.
Second, evidently you have gaps for days 20000 and 20001 which were at a weekend. dow() returns 6 for Saturday and 0 for Sunday from daily dates (for which 0 is 1 January 1960).
. di dow(20000)
6
. di dow(20001)
0
. di %td 20000
04oct2014
So, either set up a business calendar to exclude weekends and holidays, or decide that you want just to use whatever is available within particular windows based on daily dates.
Third, your wording is not precisely enough to make your problem unambiguous to anyone who doesn't routinely deal with your kind of data. It seems that you seek a cumulative (running) sum but the window could just be one window (as your question literally implies) or a moving window (which I guess at). The function sum() gives cumulative or running sums: see help sum(). Just possibly,
bysort cusip8 (date): gen wanted = sum(AR)
is a start on your solution. Otherwise, ssc describe rangestat shows you a command good for moving window calculations.
There are hundreds of posts in this territory on Statalist.

Slice a measure based on only one attribute in SSAS Tabular

I am trying to create a measure which should slice the value based on only one dimension in SSAS tabular.
e.g the cube has a measure Population. and it has dimensions Country and time the data is something like:
Crty_A : 2018 :100
Crty_A : 2017 :200
Crty_B : 2018: 50
Crty_C : 2018: 25
The data in the measure should get aggreted only at country level. like when only country name is selected the data should be like:
Crty_A :300
Crty_B : 50
Crty_B : 25
But if time and the measure is selected the data should be:
2018 :100
2017 :200
2018: 50
2018: 25
is there any way this can be achieved?
You should be able to add simple SUM into your formula that sums the entire column. Save that as your measure and then when you bring the measure into the downstream application (Excel, PowerPivot, PowerBI, ETC) the slicing should already be applied to that measure based on the filters being applied. I'm assuming that you have a star schema and all the tables appropriate relationships.
Measure_Name:=SUM(TableName[Population])

MDX YTD Not working

What am I doing wrong??? Cannot get YTD working.
RUNNING:
With
MEMBER [measures].[YTDFees] AS
Aggregate (YTD([Date Dim].Year.CurrentMember),[Measures].[Fees])
SELECT {[Measures].[Fees],
[Measures].[YTDFees]
} ON COLUMNS,
{[DATE Dim].[Year].Children*[Date Dim].[Month].children } ON ROWS
FROM [CheckCashingView]
GETTING:
Fees YTDFees
2013 1 6230939.22 6230939.22
2013 2 7856979.01 7856979.01
2013 3 7058780.18 7058780.18
2013 4 6144556.08 6144556.08
2013 5 6704988.58 6704988.58
2013 6 6298429.00 6298429.00
Probably you didn't mark your time dimension as a "Time" dimension in the SSAS option. Go to the SSAS Solution Explorer, select your Time dimension and open this dimension. Select the name of your Time dimension in the Attributes section make sure that in the dimension properties there is a "Time" in the Type properties.

MDX query to compare different years

I am new to MDX and wondered if it is possible to create a query that shows a Sales amount per Year and per Month on two different axes, even if the sales date is a single dimension.
Something like:
Sales | 2010 | 2011 | Diff
---------+-----------+------------+----------
Jan | 1234,00 | 2345,10 | +80%
Feb | ...
...
EDIT: Added mondrian to tags, because there seem to be possibilities with other MDX implementations not available in mondrian.
Yes the solution is around calculated members :
Let's imagine your initial MDX looks like :
Select
{ [Calendar].[Year].[2010],[Calendar].[Year].[2011] } on 0,
{ [Calendar].[Months].members } on 1
from [Cube]
You can add a calculated member in the [Year] hierarchy :
With
Member [Calendar].[Year].[Diff] as [Calendar].[Year].[2011] / [Calendar].[Year].[2010]-1, FORMAT_STRING='percent'
Select
{ [Calendar].[Year].[2010],[Calendar].[Year].[2011], [Calendar].[Year].[Diff] } on 0,
{ [Calendar].[Months].members } on 1
from [Cube]
You can also add a more elegant and flexible solution, by using utility or statistical dimensions. Those dimension instead of holding data define transformations / functions and the output will not be exactly the one you're looking, but it's an interesting concept.
The problem can be solved with the ParallelPeriod function:
WITH MEMBER [Measures].[Einheiten Vorjahr]
AS '(ParallelPeriod([Year],1),
[Measures].[quantity])'
SELECT {[Measures].[quantity],[Measures].[Einheiten Vorjahr]} ON COLUMNS,
[date].[2010].children on rows
FROM salesorderitems