MDX - How to access only a given level of a hierarchy - ssas

I have a hierarchy that follows the following pattern:
Date - Dimension name
DateID - Hierarchy name
Year - Level1 name
Month - Level2 name
Day - Level3 name
I want to get the number of hotel stays per month (level2), without it being expanded by year (level1)
Right now, I have the following MDX query, which kind of works but gives me 24 months (12 for each year) instead of what I want which is only 12 months (the total per month regardless of the year):
select [Measures].[Booking id] ON COLUMNS,
[Date].[Month].MEMBERS ON ROWS
from [grupo1_hotel_booking]
Any ideas how I might be able to solve this?

For a user hierarchy like that there are attribute hierarchies in the cube.
So maybe something like [Month].[Month].MEMBERS
The attribute hierarchies may be hidden by the cube designer.

Related

MDX: return last value for selected items in Power BI

This is a question regarding SSAS Cubes, MDX formulas and Power BI.
I have a measure with the active members per each month. So when I select for example 2018 it shouldn´t aggregate but return the last available month with active members, and if I break down by month it should give the active members for each month.
So I have this formula which works almost fine if querying in MS Management Studio:
with member [Measures].[Last existing SOCIOS] AS
Max(
EXISTING [DIM FECHA].[Jerarquía].[MES NOMBRE].members,
iif([Measures].[ACTIVOS] = 0,null,
[Measures].[ACTIVOS])
)
select {[Measures].[Last existing SOCIOS]} on columns,
[DIM FECHA].[MES NOMBRE].members on rows
from [cubo_Compromisos]
where [DIM FECHA].[AÑO].&[2018]
I would prefer to have the november value returned at the 'All' level. But this is not my main problem. The real issue is that when I use this measure in Power BI it behaves differently: when selecting multiple months it ignores the selected values and just returns the last value for the whole year.
In the screenshot below I have added the value returned by the KPI Card because that is the value that I want returned:
If I select items like this it does it right, but I need it to select all months, and not just one because I am using this measure along others:
Does anyone know the right MDX function to use or an alternative?
Edited: 23-11-2018
It does the same in a Pivot Table connected to a SSAS Cube.When I add the date dimension to the table it works fine. But when using the date dimension and filtering it without the dimension added as rows it returns the value for the whole year.
The function you are looking at is LastChild. Last Child on the upper level of the hierarchy will return the value you are looking at.
I think that function can be used in the Cube design in SSAS - then this will be the standard behavior. If you want to do it with a query you need to do something like:
SELECT [Date].[Fiscal].[Fiscal Quarter].[Q1 FY 2002].LastChild ON 0
FROM [Adventure Works]
To get the last month of the 1st quater (I used example from microsoft and another post on the subject )

How to get count of all currently selected members of dimension

I have got a cube with date dimension:
Period
- Year
-- Quarter
--- Month
---- Date
I need to get count of all dates, selected by user (f.e. in Excel). I have tried to use calculated members like:
[Period].[Period].CurrentMember.children.count
It is good when 1 month is selected. In other ways (selected only few dates or Quarter) it returns the count of children of the next level of hierarchy.
Descendants([Period].[Period],[Period].[Period].[Date]).count
Descendants([Period].[Period].CurrentMember,[Period].[Period].[Date]).count
So I tried to use Descendants. The results are good when 1 element on any level is selected. But one you select f.e. 2 month in one Quarter - it gives counts of all elements.
How can I get count of all selected elements on Date level?
I have also tried:
[Period].[Period].[Date].count
[Period].[Period].[Date].CurrentMember.count
COUNT([Period].[Period].[Date])
COUNT([Period].[Period].[Date].CurrentMember)
To work out multiselect in Excel, you can try Dynamic Set technique. Assume your [Period] dimension has [YQMD] hierarchy, then try the following
CREATE DYNAMIC SET SelectedDates AS (
[Period].[YQMD].[Date] )
CREATE MEMBER CURRENTCUBE.[Measures].[SelectedDatasCount] AS (
SelectedDates.count
)
Refer to this SO article and MSDN discussion. Unfortunately, Mosha's article is no longer available.
Caveat - solution with Dynamic Set can hinder query performance.

MDX SSAS query issue with Linkmember and filter 2 date timensions

I need to compute the aggregate of Opportunities Count that are active at a time (which is defined by period between start date and closing date) Not just for that period but for over all...
Opportunities Count for 2016 should include the sum of opportunities from NULL : 2015 and those that are closed in 2016:NULL.
Same thing for month and year
I have the following query that works but is giving me incorrect results for quarter, Month, date level. But gives the correct results for Year. I guess it is because of non unique key names in both dimensions
with member [Measures].[cumulative_count]
as
aggregate({NULL:[Time Dimension].[Year-Qtr-Month-Date].currentmember.lag(1) } *
{LINKMEMBER([Time Dimension].[Year-Qtr-Month-Date].currentmember.lead(1),[Opportuntity Close Dt].[Year-Qtr-Month-Date]):NULL}
,[Measures].[Opportunities Count])
SELECT [Measures].[cumulative_count] on columns,
[Time Dimension].[Year-Qtr-Month-Date].[Month].members on rows
from
AdventCube
I guess I am running into an issue with ALL member as specified in the link
http://richardlees.blogspot.com/2011/06/linkmember.html
But to override the ALL member I am running into syntax errors. Could anyone please help?

MDX expressions to aggregate data at certain level for calculated member

For now sometimes I have problems with creating difficult calculated members in SSAS. Is it possible to make case which will SUM certain measure on certain level when user choose another certain level of dimension? For example we have standard time dimension with 4 levels:
Year
Month
Week
Day
Also we have some measure orders which have default function SUM in properties.
Which case do we need to calculate this: sum all orders in week which including current day which we have chosen already.
Also could you recommend me some nook or source for level up my mdx knowledge?
Thanks a lot.
Yes, it's possible, when you use MDX functions, which are connected with levels.
Here is an example with Year > Quarter > Month > Day hierarchy:
Use MDX calculated member to have a SUM of upper level member children (including selected one):
The same if you want to create calculation inside the cube:
CREATE MEMBER CURRENTCUBE.[Measures].[SameLevelMembers]
as SUM({[Report Date].[Report Date].CurrentMember.Parent.Children},[Measures].[Count]),
VISIBLE = 1 ;
And a result in cube browser:
Hundreds of articles you can find there: http://ssas-wiki.com/w/Articles#MDX
I also like this one: http://mdxpert.com because of well-structured info.

How to I get YTD to work over multiple hierarchies

I have a Dimension [Time] on my cube. I have the following properties on my time dimension.
Date &[2015/12/25]
Month &[2015/12]
Year &[2015]
Week &[2015wk52]
Arranged into 2 hierarchies.
[Time].[Y - M - D]
Year
Month
Date
and
[Time].[Y - WK]
Year
Week
Date
I also created a measure
[Measures].[Foo YTD] AS
AGGREGATE(YTD(), [Measures].[Foo])
This seems to work great when I use the Y M D dimension in excel. But when I use the Y WK hierarchy, all my weeks return the same data.
What am I doing wrong?
My attribute relations should be correctly setup I think.
This maybe your problem.
In the definition of the YTD function: https://msdn.microsoft.com/en-us/library/ms146039.aspx
It has this remark:
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.
You could prove that this is your problem by trying the PeriodsToDate option - if it then works you know that it is the attribute type that is to blame.