I want YTD amount for each category in my MDX query - ssas

I've one MDX query where i want to show each of my product month wise count and along with that want to show YTD, MTD, WTD etc.
I've first created following MDx query on Adventure Works which give me YTD but its shows each months. instead i need output as below and I want to provide current month+year(Mar 2015) in MDX filter or where clause
EXPECTED Results:
Category YTD
--------- ------
Bike 4500
Accessories 78000
Clothing 8900
Can you please correct below MDX query to get above results sets
SELECT
{
([Product].[Category].CHILDREN,[Measures].[Order Quantity])
} ON 0,
{
YTD([Date].[Calendar].[Month].[August 2008])
} ON 1
FROM [Adventure Works];
or i've built another MDX query which give same results either one should be corrected to show above EXPECTED results.
SELECT
{
([Product].[Category].CHILDREN ,[Measures].[Order Quantity])
} ON Axis(0),
{
PERIODSTODATE([Date].[Calendar].[Calendar Year],[Date].[Calendar].[Month].[August 2008])
} ON Axis (1)
FROM [Adventure Works];

I don't think I have the same version of the AW cube as you (or what version of SSAS you are using), but try this. In the 2014 multidimensional cube, I have to change the measure to Order Count rather than quantity and change the date to March 2012 to get data back.
WITH MEMBER [Date].[Calendar].[CalendarYTD] AS
Aggregate(
YTD([Date].[Calendar].[Month].[March 2015])
)
SELECT
[Date].[Calendar].[CalendarYTD] ON COLUMNS,
[Product].[Category].Children ON ROWS
FROM
[Adventure Works]
WHERE
[Measures].[Order Quantity]

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 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:

MDX query for Microsoft Adventure Work DW 2012

It's the first time I touch MDX and I would like to get the query
Get the average Internet Sales Amount over different cities and different product categories over two fiscal years 2007 and 2008.
The following is my MDX query, but it failed to compile.
SELECT
{ [Geography].[City].CHILDREN } ON COLUMNS,
{ [Product].[Category].CHILDREN } ON ROWS
FROM [Adventure Works]
WHERE (
[Measures].[Measures].[Internet Average Sales Amount],
[Date].[Fiscal Year].&[2007],
[Date].[Fiscal Year].&[2008]
)
The above query come with an error
Query (7, 1) The Fiscal Year hierarchy is used more than once in the Crossjoin function.
Try the following. : is the range operator. For more information click.
SELECT
{ [Geography].[City].CHILDREN } ON COLUMNS,
{ [Product].[Category].CHILDREN } ON ROWS
FROM [Adventure Works]
WHERE (
[Measures].[Measures].[Internet Average Sales Amount],
[Date].[Fiscal Year].&[2007] : [Date].[Fiscal Year].&[2008]
)
It's been a while since I used MDX, but I think you will have to change more then that to get the desired result.
It's the first time I touch MDX, I am still confusing with SQL query.
For instance, if we are looking for Internet Sales Amount over different cities and different product categories.
According to the desired requirement, is the following MDX query COULD fulfill the requirement.
SELECT
{ [Geography].[City].CHILDREN } ON COLUMNS,
{ [Product].[Category].CHILDREN } ON ROWS
FROM [Adventure Works]
WHERE [Measures].[Internet Sales Amount]
I have a little bit confuse in SELECT and WHERE clause
What I expect the above statement is something like this, one axis shows all possible cities and another one shows all possible product category, and each cell is the aggregated Internet Sales Amount.
For instance.
New York | Tokyo | ...
Car $123 | $50 | ...
Toys $456 | $100 | ...
I.e. New York has $123 Internet Sales Amount for Car
Is the MDX query fulfill my expectation?

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

MDX Year on Year Sales by Months

I'm stuck on a MDX query, I'm trying to retrieve the following results:
[Time].[2009] [Time].[2010]
[Time].[Months].Members [Measures].[Sales] [Measures].[Sales]
So I would like to compare the sales which were in 2009 against 2010 by month.
In terms of a chart I would have two series one for 2009 and 2010, the y axis would be the sales value and the x axis would be the month.
My query looks like this:
SELECT {[Time].[2009], [Time].[2010]} ON COLUMNS,
[Time].[Months].Members ON ROWS
FROM [SalesProductIndicator] WHERE [Measures].[Sales]
It gives me this error:
Mondrian Error:Dimension '[Time]' appears in more than one independent axis.
Thanks in advance
SELECT {[Time].[2009], [Time].[2010]} ON 0,
[Time].[Months].Members ON 1
FROM [Your Cube Name] WHERE [Measures].[Sales]
I based that on this query (below) that I've tested on the Adventure Works sample cube from Miscrosoft:
SELECT {[Ship Date].[Fiscal Year].&[2002], [Ship Date].[Fiscal Year].&[2003]} ON 0,
[Ship Date].[Month of Year].Members ON 1
FROM [Adventure Works] WHERE [Measures].[Sales Amount]
UPDATE:
Based on your query I'm not sure why it is working without specifiying a hierarchy on your cube query (like [Time].[2010] instead of [Time].[Hierarchy Name].[2010]) but could you try this:
SELECT EXISTS([Time].Members, {[Time].[2009], [Time].[2010]}) ON COLUMNS,
[Time].[Months].Members ON ROWS
FROM [SalesProductIndicator] WHERE [Measures].[Sales]
Thanks