wrong result of parallelperiod() for DATE in MDX - schema

I want to extract data for same period last year and last month.
for this i am using Parallelperiod(), for eg
PARALLELPERIOD([date].[year],1,[date].[date].[20-Sep-2014]) ,
for which I am getting output : 21-Sep-2014
and
PARALLELPERIOD([date].[month],1,[date].[date].[20-Sep-2014]) ,
for which I am getting output : 16-Aug-2014
Same function would throw some other date for some other month
Can you guide about the issue, where i am doing wrong or if there is some other alternative to this?

You must have some dates that do not exist in the cube.
What the PARALLELPERIOD function is doing is saying ok we are 262 members at the [date] level into 2014 - then it goes to 2013 and finds the member at the [date] level that is also 262 members in. Therefore unless you have complete sets of dates in your cube this function will return surprising results.
Therefore the solution is to ensure that all historical dates are represented in the cube. These extra dates should not cause any extra overhead as they will be creating empty space in the cube which is dealt with very well by SSAS

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 )

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?

ParrellPeriod not returning what I expect

I have yearly sales goals in a measure called "Target" and a date dimension called DimCalendar.
Looking at the underlying data, I'm thinking I should get a value different than what the below query returns. It's my understanding that this query will get the value for the "Target" measure where the associated year is 2016 (one year in the future or -1) and for a specific account.
SELECT
{[Measures].[Target]} on columns,
{ParallelPeriod(
[DimCalendar].[Year].[Year]
,-1
,[DimCalendar].[Year].&[2015])} on rows
FROM [MySalesCube]
WHERE { [Account].[Account].&[2025] }
This query returns
1944768
However, the underlying data seems to add up to only 162064
Nope, looks like there is an issue with the data after all after using the cube browser. Got to go revisit my ETL process.
This is what you have specified:
ParallelPeriod(
[DimCalendar].[Year].[Year]
,-1
,[DimCalendar].[Year].&[2015])
It means the following:
Take the year 2015
Then jump the specified number of periods, in your case -1, using the level specified, in your case [Year]
The following should (I think) be a simplified but equivalent version - if the first argument is missed out then it just uses the level of the third argument:
ParallelPeriod(
-1
,[DimCalendar].[Year].&[2015])
Although I think you can just use lag to make everything more readable:
[DimCalendar].[Year].&[2015].LAG(-1)
Then again there is no point using 1 or -1 inside lag, as we have the functions NEXTMEMBER and prevMEMBER this could just be simplified to the following:
[DimCalendar].[Year].&[2015].NEXTMEMBER

mdx datediff error

select measures.name on 0,
datediff("d", [Fecha].[Date].currentmember.member_value, [Dim Date].[Date].currentmember.member_value) on 1
from cube
Error: Execution of the managed stored procedure datediff failed with
the following error: Exception has been thrown by the target of an
invocation.Argument 'Date1' cannot be converted to type 'Date'
Is there any requirements to do datediff in mdx?
In the dimension these member are defined as datetime, not sure if this influence in anyway the result...
Update: I solved the problem by making the calculation at the datasource view and at the cube I added a measure that I could use in MDX to create the indicator that I needed. Of course this is all using SSAS for testing the result and SSDT for creating the members. I hope this approach helps a lot of people even though i don't know if this is the best case scenario. Happy MDX ;)
By default, the axis will show, not the member_value, but the member name, which is always a string. The Member_Value is a measure.
With Member MyDateDiff as
datediff("d", [Fecha].[Date].currentmember.member_value, [Dim Date].[Date].currentmember.member_value)
Select
(Measures.MyDateDiff, Measures.Name) on 0
(Fecha.Date.Members, [Dim Date].[Date].Members) on 1
From cube
EDIT
I'm still new to this too, but after your comments, I thought I should elaborate on the process I went through to get similar queries right.
First, make sure you are getting the data you think you are. Get those Member_Value measures into the Columns dimension:
With
Member FechaDate as
[Fecha].[Date].currentmember.member_value
Member MyDate as
[Dim Date].[Date].currentmember.member_value
Select
(Measures.FechaDate, Measures.MyDate) on 0
(Fecha.Date.Members, [Dim Date].[Date].Members) on 1
From cube
Are you getting date values? If yes, try out your datediff function. If not, check the dimension definitions. I wouldn't be surprised to find the the ValueColumn of one of your attributes was set to the key field instead of the date value field, or some such thing.
You may need two steps, but the date add method should be fine. The Member approach from Bill is good, but it returns it as a string, not a date object. If it's in the correct format, you should be able to do:
Member MyDate as
DATEDADD("d", 1, VBAMDX!CDate([Dim Date].[Date].currentmember.member_value))
Depending on how your date string ends up formatted, you may have a little more work to do.

Aggregation of recursive day-level calculations

I'm trying to set up a cube calculation. My current remit is that I will receive exchange rates, and these will be sent at the start of the month. Sometimes they will change during the month, and I will receive a rate to use for that currency onwards.
The initial problem is that LastNonEmpty uses the granularity questioned, which means when I query by day most days do not have exchange rates, so the calculations fail. I replaced the exchange rate measure, initially with a recursive calculation, but later with the following:
WITH
MEMBER [Measures].[EOD]
AS
Aggregate({NULL:[Date].[Calendar Y M D].CurrentMember}, [Measures].[End Of Day Rate])
So, when viewed on the date dimension, it will get the most recent exchange rate. This allows a daily calculation as follows:
MEMBER [Measures].[Converted]
AS
SUM
(
{[Currency].[Currency].[Currency] * [Date].[Calendar Y M D].CurrentMember},
(
(
[Measures].[Sales]
)
/ [Measures].[EOD]
)
)
Lastly I use this in a query:
SELECT
{
[Measures].[Converted]
}
ON COLUMNS,
NON EMPTY
{
[Date].[Calendar Y M D].[Calendar Day].&[2010-Q3-08-01] :
[Date].[Calendar Y M D].[Calendar Day].&[2010-Q3-08-31]
}
ON ROWS
FROM [Cube]
This all works fine, but ideally I'd prefer to query by year/month, as these are month-end reports. I can sum all this in the code tiers, but I'd rather have MDX that can do it itself.
The problem is that the calculations are done almost recursively at the day-level, then I'd like them rolled up to the month (Or even year) level.
I did try the currency conversion wizard, swapping the exchange rate for the time-aggregated one above, but attempting to browse the cube in SSMS locked the server as it tried to do the aggregation for the whole calendar :(
Any suggestions on what approach is best to take?
If you used views or named queries in the DSV instead of tables, then you could adjust the view or named query to limit the data to days where you have loaded exchange rate data. I'm not sure if this would meet your business need, but you could eliminate the empty data issues through this approach. After all, there's not much use to loading data that doesn't contain a value or, worse, preloading a guestimated exchange rate that would have to be overwritten once the actual numbers are available.