I am using SSRS to create reports. For the metrics i am pulling out data from the analysis services. I want to modify the mdx query created by the query designer to include data only from past 6 months. The query looks like this right now:
SELECT NON EMPTY { [Measures].[Cumulative Count] } ON COLUMNS,
NON EMPTY { ([Work Item].[Microsoft_VSTS_Common_Discipline].[Microsoft_VSTS_Common_Discipline].ALLMEMBERS * [Date].[Year Month Date].[Month].ALLMEMBERS ) }
DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM
( SELECT ( { [Work Item].[System_WorkItemType].&[Task] } ) ON COLUMNS
FROM
( SELECT ( { [Date].[Year Month Date].[Year].&[2010-01-01T00:00:00] } ) ON COLUMNS FROM [Team System]))
WHERE ( [Work Item].[System_WorkItemType].&[Task] ) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS*
Here I am pulling out the cumulative count of the work items where the work item type is task and the year of the work item is 2010. However instead of pulling out all the months from 2010 i want past 6 months. Does anyone know how can i do this in the above query.
Create a new calculated member that returns data for only the last 6 months.
I have done this in the past by adding VBA functions to my MDX (Analysis Services allows this). You can get the current date, work back 6 months, grab the month/year, and write a string in the same format as your member names. Then use StrToSet to include this string in your MDX query.
Related
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 )
I've been tasked with a rather odd Time intelligence function by my finance group that I'm trying to puzzle out.
I've been asked with creating a measure within our SSAS Cube to allow for seeing previous quarter to date based on how far we are in the current quarter. But instead of seeing a standard idea of days elapsed currently versus days elapsed previously, they would like to see days remaining versus previous days remaining.
What I mean by that is, take 1/22/2015 for example. We have 48 days remaining in our current quarter, which I have by means of a calculated measure. I need to find the corresponding working day from the previous quarter where it is also at 48 days remaining.
At that point I could create a date range with some aggregate functions off of the first date in the previous quarter to the corresponding date found in the above and come up with what they are looking for.
The best idea I've had so far is to possibly do this in the database section itself, by creating a new column that is essentially the calculated number of days remaining but stored. But at that point I'm not sure how to take a calculated measure in SSAS and filter a previous quarter date member to use that property as it were.
Do you have an utility dimensions in your cube? We have one called TimeCalculations. In there we have things such as CurrentValue, MTDValue, PrevEquivMTD, Past7Days .... I think your new logic would fit in with such a dimension.
Here is an example of PrevEquivQTD against AdvWrks that I just had a play with. Guessing this doesn't really help your scenario but I had fun writing it:
WITH
SET [NonEmptyDates] AS
NonEmpty
(
[Date].[Calendar].[Date].MEMBERS
,[Measures].[Internet Sales Amount]
)
SET [LastNonEmptyDate] AS
Tail([NonEmptyDates])
SET [CurrQ] AS
Exists
(
[Date].[Calendar].[Calendar Quarter]
,[LastNonEmptyDate].Item(0)
)
MEMBER [Measures].[pos] AS
Rank
(
[LastNonEmptyDate].Item(0)
,Descendants
(
[CurrQ]
,[Date].[Calendar].[Date]
)
)
MEMBER [Measures].[PrevEquivalentQTD] AS
Sum
(
Head
(
Descendants
(
[CurrQ].ITEM(0).PrevMember
,[Date].[Calendar].[Date]
)
,[Measures].[pos]
)
,[Measures].[Internet Sales Amount]
)
SELECT
{[Measures].[pos],[Measures].[PrevEquivalentQTD]} ON 0
,[LastNonEmptyDate] ON 1
FROM
(
SELECT
[Date].[Calendar].[Date].&[20050111]
:
[Date].[Calendar].[Date].&[20080611] ON 0
FROM [Adventure Works]
);
Your Date is 1/22/2015. You want the Same Date in Previous Quarter which would be 8/22/2015.
If this is what you want, you will have to use MDX function ParallelPeriod as shown in sample below. Please replace it with your own Dimensions and Cube.
Select
ParallelPeriod
(
[Date].[Calendar Date].[Calendar Quarter], -- Level Expression
1, -- Index
[Date].[Calendar Date].[Date].&[20150122] -- Member Expression
) On 0
From [Adventure Works]
If you want the same date in the following quarter, then replace index 1 with -1.
Cheers
I want to create a calculated member. I have a time dimension hierarchy" YQM", which has Year/Quarter/Month. The calculated member should find YTD till the current month. However, the value of current month will come from database.
I have created a attribute, "CP" which returns the current month value.
Please tell me how to create the calculated member. Please note "CP" is not in the same hierarchy YQM.
I don't understand why you are using Aggregate. So, I will assume that it is there for some purpose, which you have't clarified. Now, if the members of [YQM].[Month] and [Dim].[CP] are of the same format, then you can try the code below:
Aggregate(
PeriodsToDate([Dim].[YQM].[Month].MEMBERS,
FILTER([Dim].[YQM].[Month].MEMBERS,
[YQM].[Month].CURRENTMEMBER.member_value = [Dim].[CP].FirstChild.member_value)
)
)
Why not try playing with the function YTD. The following should give you the monthly amount in the first column of data and then the YTD amount in the next column:
WITH MEMBER [Measures].[YearToDate] AS
AGGREGATE(
YTD()
,[Measures].[someMeasureInCube]
)
SELECT
{
[Measures].[someMeasureInCube],
[Measures].[YearToDate]
} ON 0,
[Dim].[YQM].[Month].MEMBERS ON 1
FROM [yourCube]
This is my actual calculated member :
([Measures].[Val Enc],[Data].[Ano - Mes].[Mes].&[2013]&[2]&[4]&[12])
I need to transform him into a dynamical calculated member. In my reports i need to see the values($) of the current month and the values of December (only December) of the previous year.
You can define that measure as a calculated member and have it display side by side with this year's values:
With Member [Measures].[Last December] as ( [Measures].[Val Enc], [Data].[Ano - Mes].[Mes].&[2013]&[2]&[4]&[12])
Select Descendants( [Data].[Ano - Mes].[Mes].&[2013], <Your month level name here> ) on Rows,
{ [Measures].[Val Enc], [Measures].[Last Dec] } on Columns
From <your cube name here>
I am a complete newbie to MDX and have been asked to work out a calculation that I am finding difficult. I've read up the basics on the language and looked at online articles but struggling to find something which can help me.
I have a Measure of TotalLogins on a day to day basis.
I have a Dimension of Date, that has Date/Month/Year/DayOfWeek attributes.
What I need to do is get the average TotalLogins over a particular month, but with the caveat of excluding Saturdays/Sundays.
I've been playing with the AVG function, the EXCEPT function and the IIF function, but cant seem to hit the nail on the head.
Here's an example of what I've been attempting:
WITH
MEMBER [Measures].[MyAvg] AS
(
AVG(Descendants ([Dim Date].[Date].CurrentMember,
[Dim Date].[Date]),
[Measures].[UniqueVisitsDay])
)
SELECT
{[Measures].[MyAvg]} ON COLUMNS,
{NONEMPTY([Dim Date].[Year Month].Members)} ON ROWS
FROM
[MyCube];
This gives me an average per month, but doesnt allow me to specify a range of months to fall between and doesnt allow me to filter the totals so that Sat/Sun arent included.
Can someone point me in the right direction?
Thanks in advance!!
Try this:
WITH MEMBER [Measures].[MyAvg] AS
AVG(
EXCEPT([Dim Date].[Day Of Week].Members,
{[Dim Date].[Day Of Week].[Saturday],[Dim Date].[Day Of Week].[Sunday]}
), [Measures].[UniqueVisitsDay]
)
SELECT { [Measures].[MyAvg] } ON COLUMNS,
NON EMPTY { [Dim Date].[Year Month].Members } ON ROWS
FROM
[MyCube];
If you want to limit your results to a specific date range, replace the 3rd row from the bottom with something like this:
NON EMPTY { [Dim Date].[Year Month].[2013 November]:[Dim Date].[Year Month].[2014 January] } ON ROWS
(of course you might need to replace the member names with their actual names, or better yet, use the keys, for example: [Dim Date].[Year Month].&[201311])