I'm not friendly with MDX and I have some difficulties to create calculated measures.
We have some data in a cube and the users would like to have also the measures of the previous month, the measures of december of last year and the measures of december of the current year.
We have our own calendar table in our database with the fields date, month, year, month number...
I have created a Calendar Dimension based on this table with the Time type (with link between date -> Days, month -> Months and year -> Years ).
I have added the measure in the cube.
I try to create the calculated measure like this :
previous month :
CREATE MEMBER CURRENTCUBE.[Measures].[MEASURE_A_PREVIOUS_MONTH]
AS ([Dim_CALENDAR].[MONTH].CURRENTMEMBER.PREVMEMBER, [Measures].[MEASURE_A])
=> OK
december last year :
CREATE MEMBER CURRENTCUBE.[Measures].[MEASURE_A_DECEMBER_PREVIOUS_YEAR]
AS IIF(ISEMPTY([Measures].[MEASURE_A]), NULL, ([Dim_CALENDAR].[MONTH_NUMBER].[12], [Dim_CALENDAR].[YEAR].CURRENTMEMBER.PREVMEMBER, [Measures].[MEASURE_A]))
=> It's good for the first year (2021-M01 to 2020-M12) but after I have a sum of all the month by year
december current year
CREATE MEMBER CURRENTCUBE.[Measures].[MEASURE_A_DECEMBER_PREVIOUS_YEAR]
AS IIF(ISEMPTY([Measures].[MEASURE_A]), NULL, ([Dim_CALENDAR].[MONTH_NUMBER].[12], [Dim_CALENDAR].[YEAR].CURRENTMEMBER, [Measures].[MEASURE_A]))
=> It's good for the first year (2019-M12) but after I have a sum of all the month by year
image of cube results
It seems i can't use the PARALLELPERIOD function because I would like a specific month (december) isn't it ?
What could be the issue?
OK find the solution, it comes from my Calendar dimension, I had a bad relation, I had the relation DATE-> MONTH_NUMBER instead of MONTH -> MONTH_NUMBER. Now it's work.
Related
Facing some trouble when comes to MDX, trying to get the Revenue PY.
Had a date dimension set up with a Year Week Date Hierarchy
when I run the below MDX, it is pointing me to 5th Sep, instead of 12th Sep.
SELECT
ParallelPeriod
(
[Date].[Date YWD].[Year]
,1
,[Date].[Date YWD].[Date].&[2017-09-11T00:00:00]
) ON 0
FROM [TestCube];
Does this mean, I have my dimension set up wrong, but the hierarchy still gives me correct dates in a week.
Above is the name column, key columns are Year Number, Week Number, Date
Any help would be much appreciated
This function is looking for same relative member a year back. First week of 2017 is W01-17 starting sunday 01-01-2017. So W37-17 is the 37th member within that year.
The first week in 2016 is W53-16 starting sunday 27-12-2015. So week 1 is the 2th member and week 36 is the 37th member.
In this hierarchy you should use the week-year instead of the date-year.
We have a relative date dimension in our cube that has member values This Year and Last Year as an example.
The user uses this set on columns against sales so they can look at Sales for this year and the same period last year.
The problem comes when they are using the Calendar Date filter to only select values for this month. If the user selects just this month, then the Last Year member disappears.
Is there a way (perhaps with scope statements) that I can tell SSAS: If the user is using these attributes and they select a specific month (or other level), then use ParallelPeriod to implicitly include the same members for the previous year so that they can see the last year sales?
If not, without using calculated members (I have so many measures that I don't want to have to duplicate them), is there a way using dimensions to show a last year value even if the user selects this year in the date dimension?
There are a few options here...
I would just add a new Calculated Member to an existing dimension,i'll add it to a Pseudo-Dimension [Time Period] dimension with something like this:
(i'm pretty sure you need to add it to an existing Hierarchy. I'll assume [Relative Time])
CREATE MEMBER [Time Period].[Relative Time].[Last Year]
AS NULL
, VISIBLE=1;
SCOPE(
DESCENDTS([Time].[YearMonthDate].[Year].MEMBERS,,AFTER)
,[Time Period].[Relative Time].[Last Year]
);
THIS = AGGREGATE(
PARALLELPERIOD(
[Time].[YearMonthDate].[Year]
,1
,[Time].[YearMonthDate].CURRENTMEMBER
)
,[Measures].CURRENTMEMBER
);
END SCOPE;
I have a Cube with a Date dimension hierarchy (Year,Semester,Quarter,Month,Day).
There are 2 measures available in the datawarehouse.
[AUD DLY] : Daily numbers
[AUD YTD] : Daily incremental YTD numbers
Hierarchy is as follows
Date - Dimension
Financial - Hierarchy
Year - [Date].[Financial].[Year]
Semester - [Date].[Financial].[Semester]
Quarter - [Date].[Financial].[Quarter]
Month - [Date].[Financial].[Month]
Day - [Date].[Financial].[Day]
Measures [AUD DLY]
Measures [AUD YTD]
I need to add a MTD field in the measures such that when the business select a particular date on their slicer in excel for e.g., 3 March 2016, MTD should be calculated as either of the following ways :
1) [AUD MTD] should be calculated by subtracting [AUD YTD] on
last day of previous month from the current selected date.
So if we select 3 March 2016 then
[AUD MTD] = [AUD YTD] on 3 March 2016 - [AUD YTD] on 29 Feb 2016
OR
2) [AUD MTD] should be calculated by adding the [AUD DLY] from first day
of the current month until the selected date in that month.
So if we select 3 March 2016 then
[AUD MTD] = SUM ([AUD DLY] from 1 March 2016 to 3 March 2016)
I created a New Calculated Member from Calculations tab in the Cube designer in the BIDS 2010. The MDX query is below. However when I try to browse the cube the [AUD MTD] values are only returning nulls.
Can someone please help what am I doing wrong ?
CREATE MEMBER CURRENTCUBE.[Measures].[AUD MTD]
AS Aggregate
(
PeriodsToDate
(
[Date].[Financial].[Month]
,[Date].[Financial].CurrentMember
)
,[Measures].[AUD DLY]
),
FORMAT_STRING = "Currency",
NON_EMPTY_BEHAVIOR = { [AUD DLY] },
VISIBLE = 1 , DISPLAY_FOLDER = 'AUD Values' , ASSOCIATED_MEASURE_GROUP = 'Measures' ;
Also the business would be using the new calculated measure in excel using the Slicer, they want to select any date and be able to view the MTD value for that month.
Also can someone please help with MDX query for both methods (1) and (2) ?
Your help much appreciated.
I think the problem with your quoted code (method 2) is that [Date].[Financial].CurrentMember must be at a level at or below the [Date].[Financial].[Month] level. Otherwise PeriodsToDate returns an empty set.
So the problem is not in your calculated member definition, but somewhere in the query in which it's being used. In that query, [Date].[Financial].CurrentMember may be returning a member at a level above Months. Hard to see without seeing the query itself.
Method (1) is more fiddly. You can get the last day of the previous month with
Ancestor([Date].[Financial].CurrentMember,[Date].[Financial].[Month]).PrevMember.LastChild
but you'd have to build in some logic for days in the first month of the financial year, which would otherwise subtract the value for a previous fin year from this year's YTD value. So I'd recommend method (2).
As far as I know selecting a date (I mean a date, not a month) in the Excel slicer will make that date the .CurrentMember. I'm a bit hesitant because Excel does generate some deeply bizarre MDX sometimes.
EDIT: Another possible problem is a hierarchy mismatch. You can select a perfectly good Day in a date hierarchy, but if it isn't in exactly the hierarchy you specify in your calculated member definition, you can get weird results. IMHO more recent versions of SSAS encourage a proliferation of attribute hierarchies and multiple "real" hierarchies, making this a real problem.
As a test can you please add this very simple measure to make sure that currentmember is behaving as expected:
CREATE MEMBER CURRENTCUBE.[Measures].[AUD MTD]
AS [Date].[Financial].CurrentMember.member_caption
If when you use the above all it returns is the All member then you know something is wrong.
You need to double-check your relationships and datatypes used within your date hierarchies as this is often the reason for time calculation problems.
This is an alternative to your measure but I suspect if the original script is not working then neither will this...
CREATE MEMBER CURRENTCUBE.[Measures].[AUD MTD]
AS SUM
(
MTD([Date].[Financial].CurrentMember)
, [Measures].[AUD DLY]
)
I have a Date dimension that I would like to check current month and current year, and then display a different Measure depending on that evaluation.
example:
MM - 04
YY -2016
Calculated member determines current month then for months prior(1-3) it shows measure Qty Shipped. For current month and beyond(4-12) it shows measure Forecast. This logic is only working with current year.
Thanks.
IIF(([02 Dates].[MM].currentmember,[Measures].[Qty Shipped])<
(
STRTOMEMBER('[02 Dates].[MM].&['+format(now(),'yyyy')+']&['+format(now(),'MM')+']')
,[Measures].[Qty Shipped]),
[Measures].[Qty Shipped],
[Measures].[Current Forecast])
Seems to do the Current Month on correctly, but doesn't move qty shipped to months 1-3.
Thanks
Does this logic look correct.
Any help much appreciated.
I have a fact table with payroll data and contains columns such employee id, dollars, start date & end date (pay period). So the granularity is not at the daily level. How can we add this fact table to my cube and link to date dimension? I have a date a typical date dimension in the cube with date, month, quarter and year.
note - the start and end date do not always fall on the sames days of the calendar month. I know it is terrible idea to somehow "convert" the grain to daily level by diving the dollar amounts by the number of days between start date and end date but i can't figure out another/better option.
As explained in the documentation, a relationship of a fact table/measure group to a dimension need not point to the key attribute/column of the dimension, it may point to any attribute (like the month attribute in your case). Then, you only can use the attribute that you linked to and attributes which have direct or indirect references from it. If you would have a reference from month to quarter and from quarter to year in your dimension, then the measures from your measure group referencing the month attribute can use quarter or year. But they cannot use days.