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?
Related
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.
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:
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]
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
I want to create a barchart with a bar for each month and some measure.
But i also want to filter on a range of day which might not completly overlap some of the month.
When that happen I would like the aggregate count for those month to only aggregat over the days that fall in my date range not get the aggregate for the whole month.
Is that possible with MDX and if it is how should the request look like?
Create a second time dimension, using a virtual dimension of the original dimension. Use one dimension in the WHERE and another in the SELECT.
This often happens anyway if some people want 'Business Time' of quarters and periods, and others prefer months. Or if you have a financial year which runs April-April.
You can use subselect. You can find more information on this page and this page:
When a member is specified in the axis clause then that member with
its ascendants and descendants are included in the sub cube space for
the subselect; all non mentioned sibling members, in the axis or
slicer clause, and their descendants are filtered from the subspace.
This way, the space of the outer select has been limited to the
existing members in the axis clause or slicer clause, with their
ascendants and descendants as mentioned before.
Here is an example:
SELECT { [Customer].[Customer Geography].[Country].&[Australia]
, [Customer].[Customer Geography].[Country].&[United States]
} ON 1
, {[Measures].[Internet Sales Amount], [Measures].[Reseller Sales Amount]} ON 0
FROM ( SELECT {[Customer].[Customer Geography].[Country].&[Australia]
, [Customer].[State-Province].&[WA]&[US]} ON 0
FROM [Adventure Works]
)
The result will contain one row for Autralia and another one for the United States. With the subselect, I restricted the value of United Stated to the Washington state.
One way I found to do it with Mondrian is as follow
WITH MEMBER [Measures].[Units Shipped2] AS
SUM
(
{
exists([Store].[Store Country].currentmember.children,{[Store].[USA].[WA],[Store].[USA].[OR]})
},[Measures].[Units Shipped]
)
MEMBER [Measures].[Warehouse Sales2] AS
SUM
(
{
exists([Store].[Store Country].currentmember.children,{[Store].[USA].[WA],[Store].[USA].[OR]})
},[Measures].[Warehouse Sales]
)
SELECT
{[Measures].[Units Shipped2],[Measures].[Warehouse Sales2]} ON 0,
NON EMPTY [Store].[Store Country].Members on 1
FROM [Warehouse]
I am not sure if the filtering will be done in SQL like below and give good performance or be run locally
select Country, sum(unit_shipped)
where state in ('WA','OR' )
group by Country