How can I solve this MDX Problem? - ssas

I want to be comparing the previous and current values, but my MDX query is giving the following error
"The CURRENTMEMBER function expects a hierarchy expression for the 1 argument."
How can I solve this problem?
My MDX query is below. please help
with member [Measures].[Growth] as ([Date].[Calendar].[Month].CurrentMember,[Measures].[Internet Sales Amount])-([Date].[Calendar].[Month].CurrentMember.PrevMember,[Measures].[Internet Sales Amount])
select
{[Measures].[Internet Sales Amount],[Measures].[Growth] }
on columns,
{([Date].[Calendar].[Month].Members)}
on rows
FROM [Adventure Works]

Change your member statement to the following:
with member [Measures].[Growth] as ([Date].[Calendar].CurrentMember,[Measures].[Internet Sales Amount])-([Date].[Calendar].CurrentMember.PrevMember,[Measures].[Internet Sales Amount])
The currentmember function works off of a hiearchy.

Related

Cumulative Sum | Exclude attribute from calculation

I am trying to do Cumulative Sum/ Running Total using the function below so the user can use any date level, but the requirement is to ignore some of the attributes from the calculation.
Function used:
SUM(NULL:Axis(1).Item(0).Item(Axis(1).Item(0).Count-1).Hierarchy.CurrentMember, [Measures].[ Number of Ticket])
Example:
The table below shows the Cumulative Sum as expected
Example - 1
Here by adding another attribute, Program Remaining, as shown below, its changes the Cumulative behavior, Because Excel will add that attribute to the grouping so it reset the cumulative sum:
Example - 2
Is there a way that I can exclude the Program Remaining attribute from the calculation (I have another 4 attributes that I want to exclude) so that the cumulative can be increased just like the first table even with adding these attribute.
I really appreciate any help
Try using the below sample query
with
member
[Measures].[Internet Sales AmountRunningtotal]
as
case when [Measures].[Internet Sales Amount] = null then null
else
sum({[Product].[Subcategory].firstchild:[Product].[Subcategory].currentmember},[Measures].[Internet Sales Amount])
end
select {[Measures].[Internet Sales Amount],
[Measures].[Internet Sales AmountRunningtotal]
} on columns,
non empty
([Date].[Calendar Year].[Calendar Year],[Date].[Calendar Quarter of Year].[Calendar Quarter of Year],
[Product].[Category].[Category],[Product].[Subcategory].[Subcategory])
on
rows
from
[Adventure Works]
So I explored the sample sent, Your only solutions is to keep the date in the inner most position, your query qouted above will break if you are not using entire members of an attribute.

How to get measure value for certain date range in MDX?

I am new to MDX and for now it looks like some hell to me.
I have a measure called Sales KG. It calculate sales amount based on table AData where I have column named Data_Date.
I need to get Sales KG value for specified range of dates.
The problem is I can't understand how to specify that range. It doesn't look like simple < and > are works here.
I totally lost and don't have much to show, but this is what I tried:
select
[Sales KG] on Columns
from [Model]
where ([Format_TT].[Супермаркет], [Data_Date].&[20160101] : [Data_Date].&[20170101])
But it tells me that can't convert string "20160101" into date type. And probably this is not what I want. I want it to be single value for date range in single cell.
What to do?..
Take a look at the below sample they will help .
Please note that "Date" is a dimesnion in the cube, which has an attribute "[Date]" in it. "[Measures].[Internet Sales Amount]" in the cube. It is necessary to have them defined in the SSAS project, If one of them is not defined in the project but exists in the base tables of star schema it will not work. MDX can only see objects defined in the SSAS project
//First way
select
[Measures].[Internet Sales Amount]
on columns
from [Adventure Works]
where {[Date].[Date].&[20130101]:[Date].[Date].&[20130131]}
Second way
select
[Measures].[Internet Sales Amount]
on columns,
{[Date].[Date].&[20130101]:[Date].[Date].&[20130131]}
on rows
from [Adventure Works]

Get grand total by column

I want to calculate the grand total of a given measure in MDX by a column dimension (time dimension)
This is my MDX code:
SUM(
([DIM_TIME].[PERIOD]),
[Measures].[VALUE]
)
Basically, this is what I want to get :
But this is what I get:
Thanks for any possible help
Take a look at the sample query
with member
[Measures].[Internet Sales AmountTotal]
as
case when [Product].[Category].currentmember is [Product].[Category].defaultmember then null
else ([Product].[Category].defaultmember,[Measures].[Internet Sales Amount])
end
select
({[Date].[Calendar Year].&[2012],[Date].[Calendar Year].&[2013]},
{[Measures].[Internet Sales Amount],[Measures].[Internet Sales AmountTotal]})
on columns,
{[Product].[Category].members}
on rows
from [Adventure Works]

How to filter measure multiple times in cube

I need to product a report from my cube that looks something like the following.
(dummy data)
Where it lists sales and gross profit for today, this week, the period and year to date across the products category.
My cube is setup as follows
A date dimension
And the cube itself
Currently I have not implemented the product category pieces.
I'm struggling with how to write an MDX query that can return the sales/gross profit for a single day and then week and so on.
I can return it by itself like so
SELECT {[Measures].[Gross Profit],[Measures].[Price]} ON COLUMNS
From [Cube]
WHERE [Date].[Date Key].[2015-04-22];
and so on for the other various types (week etc), but I'm unsure as how to apply the where filter to the columnn itself rather than the overall query, or if this is even the correct way to do it and I should be making multiple MDX calls that I then compose in my app that will use this.
Can anyone give me a pointer in the right direction here?
EDIT: Seems to mostly work using the approach #Akshay Rane described however I cannot get one of my measures to work
MEMBER [This Week] as
(PeriodsToDate([Date].[Fiscal Week Date].[Fiscal Week],StrToMember('[Date].[Fiscal Week Date].[Date Key].&[' + '20140401' + ']'))
,[Measures].[Merchandise Gross Profit])
Gives me an error:
The function expects a string or numeric expression for the argument. A tuple set expression was used.
Any pointers here?
You will have to create separate Calculated Members for each time interval you want to aggregate the data upon.
This can be done in [Adventure Works] cube as follows.
WITH
MEMBER [Today] as
([Measures].[Internet Sales Amount], [Date].[Date].CURRENTMEMBER)
MEMBER [Last Week] as
AGGREGATE (
{ [Date].[Date].CURRENTMEMBER.lag(6) : [Date].[Date].CURRENTMEMBER }
, [Measures].[Internet Sales Amount]
)
SELECT
{ [Today], [Last Week] } ON 0,
{ ([Product].[Product Categories].[Category], [Date].[Date].[Date]) } ON 1
FROM
(
/*FILTERING ON SPECIFIC DATE USING SUBCUBE*/
SELECT [Date].[Date].&[20070715] ON 0
FROM [Adventure Works]
)
If you can take the different levels of date from the same user hierarchy then something like this is possible:
SELECT
{
[Date].[Calendar].[Month].&[2006]&[7]
,[Date].[Calendar].[Date].&[20050220]
}
*
{
[Measures].[Order Quantity]
,[Measures].[Internet Sales Amount]
} ON COLUMNS
,{[Product].[Category].Children} ON ROWS
FROM [Adventure Works];
The above produces results like this:

SSAS 2008R2 mdx query using Date and Parent Child in WHERE clause

I newbie in olap using AdventureWorksDW2008R2 db and Adventure Works 2008R2 olap with Adventure Works cube.
I want to write an mdx query as per the result using T-SQL: -
select
FactResellerSales.OrderDateKey,
SUM(FactResellerSales.SalesAmount) as 'Reseller Sales Amount'
from FactResellerSales with (nolock)
inner join DimEmployee on DimEmployee.EmployeeKey = FactResellerSales.EmployeeKey
where
FactResellerSales.OrderDateKey=20070901
and DimEmployee.FirstName='Jae' and DimEmployee.LastName='Pak'
group by FactResellerSales.OrderDateKey
The result:
OrderDateKey Reseller Sales Amount
20070901 415046.9295
Using the mdx query, I can only execute the following: -
SELECT [Measures].[Reseller Sales Amount] ON COLUMNS,
NON EMPTY [Date].[Date].members ON ROWS
FROM [Adventure Works]
WHERE [Employee].[Employees].&[291]
The result is from July 1, 2006 to June 1, 2008 with the respective Reseller Sales Amount summary for each day.
My questions are, within the mdx query WHERE clause how do I:
a) Filter by date which is September 1, 2007? It doesn't accept the date dimension.
b) Filter by Employee using the name 'Jae B. Pak' which is in a multi-level hierarchy instead of using the EmployeeKey which is 291.
You need to crossjoin the employee dimension with the date you are interested in.
The following will give you just the value;
SELECT { [Measures].[Reseller Sales Amount] } ON COLUMNS
FROM [Adventure Works]
WHERE ({ [Employee].[Employee Department].[Employee].[Jae B. Pak]},
{[Date].[Date].&[20070901] })
The where clause in MDX is a slicer which behaves differently from the SQL where clause (worth reading about). The following cross join on rows would provide the same result without using the slicer, but will include the dimension attributes within the result.
SELECT { [Measures].[Reseller Sales Amount] } ON COLUMNS,
CROSSJOIN({ [Employee].[Employee Department].[Employee].[Jae B. Pak]}, {[Date].[Date].&[20070901] }) ON Rows
FROM [Adventure Works]
and finally, if you want to return based on a 'SQL Like', you can use instr (the following gives all employees where the name include ja)
SELECT [Measures].[Reseller Sales Amount] ON COLUMNS,
{FILTER([Employee].[Employees].allmembers,
instr([Employee].[Employees].currentmember.member_caption,'Ja')>0) * [Date].[Date].&[20070901]} ON ROWS
FROM [Adventure Works]
hopefully that will get you going