How to Apply group by on mdx Query - mdx

Working pentaho dashboard trying to generate report to get transaction count per day/Week/Month between two date.
Below MDX Query return transaction count 1 because 'created' is not group by
WITH
SET [~COLUMNS] AS Filter([created].DefaultMember.Children, [created].CurrentMember.name >= "2014-10-01" AND Left([created].CurrentMember.Name, 10) <= "2014-10-02")
SET [~ROWS] AS
{[markup].[markup].Members}
SELECT
NON EMPTY CrossJoin([~COLUMNS], {[Measures].[Transaction Count]}) ON COLUMNS,
NON EMPTY [~ROWS] ON ROWS
FROM [transaction]
How to i can group column '[created]'

Why not just move the measure into the WHERE clause:
WITH
SET [~COLUMNS] AS Filter([created].DefaultMember.Children, [created].CurrentMember.name >= "2014-10-01" AND Left([created].CurrentMember.Name, 10) <= "2014-10-02")
SET [~ROWS] AS
{[markup].[markup].Members}
SELECT
NON EMPTY [~COLUMNS] ON COLUMNS,
NON EMPTY [~ROWS] ON ROWS
FROM [transaction]
WHERE [Measures].[Transaction Count]

Related

MDX query to except specific date from date range

I am need to delete all 2 month from set. This code return all date range without excepting 2 month.
SELECT
{[Measures].[In]} ON COLUMNS,
EXCEPT([Date].[2014].[1] : [Date].[2016].[2], [Date].[Month].[2]) ON ROWS
FROM [Shop hourly]
Print screen for whytheq
My decision based on whytheq answear. I create a dimension for all kind of dates, and except them. Example:
SELECT {[Measures].[In sum]} ON COLUMNS,
NON EMPTY
{[Shop].[11], [Shop].[22], [Shop].[33]} *
Except([Quarter].Children, [Quarter].[2]) *
[Month].Children ON ROWS
FROM [Shop hourly]
WHERE
([Date].[2013].[1].[1] : [Date].[2016].[1].[1]) *
Except([Year].Children, [Year].[2014])
In AdventureWorks I can do the following:
SELECT
[Measures].[Internet Sales Amount] ON 0
,NON EMPTY
Except
(
[Date].[Calendar].[Month].&[2005]&[7]
:
[Date].[Calendar].[Month].&[2008]&[7]
,Exists
(
[Date].[Calendar].[Month].MEMBERS
,[Date].[Calendar Quarter of Year].&[CY Q3]
)
) ON 1
FROM [Adventure Works];
So adapting the above to your cube maybe looks like the following:
SELECT
{[Measures].[In]} ON COLUMNS
,Except
(
[Date].[2014].[1] : [Date].[2016].[2]
,Exists
(
[Date].MEMBERS
,[Date].[Month].[2]
)
) ON ROWS
FROM [Shop hourly];

MDX Sort By Month

I am trying to put together my first query for a pentaho CDE dashboard chart.
Starting Query
WITH
SET [~COLUMNS] AS
{[DimProgram.Name].[Name].MEMBERS}
SET [~ROWS] AS
{[DimTime.CalendarYearMonth].[CalendarYearMonth].MEMBERS}
SELECT
NON EMPTY
CrossJoin
(
[~COLUMNS]
,{[Measures].[SubmissionCount]}
) ON COLUMNS
,NON EMPTY
[~ROWS] ON ROWS
FROM [PSE_FactSubmission];
This query returns the data I want but needs to be tweaked a bit to be ready for actual use. I want to sort by date descending and limit to only the past 12 months.
I've read several webpages on sorting in MDX, but haven't been able to put together a query that will run. When the query doesn't run just an "Error" prompt.
Ordering Attempt
WITH
SET [~COLUMNS] AS
{[DimProgram.Name].[Name].MEMBERS}
SELECT
NON EMPTY
CrossJoin
(
[~COLUMNS]
,{[Measures].[SubmissionCount]}
) ON COLUMNS
,NON EMPTY
Order
(
[DimTime.CalendarYearMonth].[CalendarYearMonth].MEMBERS
,[DimTime.CalendarYearMonth].CurrentMember.Member_Key
,DESC
) ON ROWS
FROM [PSE_FactSubmission];
Any tips on sorting or how to limit to the past X months would be very appreciated.
Usually a Date/Time dimension is ordered naturally in the cube design so there is no need to use Order. I don't need to with the cubes I use.
If it is in a strange order in the cube then you need to break (B) this hierarchical order by using BASC or BDESC:
WITH
SET [~COLUMNS] AS
{[DimProgram.Name].[Name].MEMBERS}
MEMBER [Measures].[orderMeas] AS
[DimTime.CalendarYearMonth].CurrentMember.Member_Key
SET [~ROWS] AS
Order
(
[DimTime.CalendarYearMonth].[CalendarYearMonth].MEMBERS
,[Measures].[orderMeas]
,BASC
)
SELECT
NON EMPTY
CrossJoin
(
[~COLUMNS]
,{[Measures].[SubmissionCount]}
) ON COLUMNS
,NON EMPTY
[~ROWS] ON ROWS
FROM [PSE_FactSubmission];
To get the most recent 12 months you can use the Tail function - better to use it against NonEmpty months:
WITH
SET [~COLUMNS] AS
{[DimProgram.Name].[Name].MEMBERS}
MEMBER [Measures].[orderMeas] AS
[DimTime.CalendarYearMonth].CurrentMember.Member_Key
SET [~ROWS] AS
Order
(
NonEmpty
(
[DimTime.CalendarYearMonth].[CalendarYearMonth].MEMBERS
,[Measures].[SubmissionCount]
)
,[Measures].[orderMeas]
,BASC
)
SELECT
NON EMPTY
CrossJoin
(
[~COLUMNS]
,{[Measures].[SubmissionCount]}
) ON COLUMNS
,NON EMPTY
Tail
(
[~ROWS]
,12
) ON ROWS
FROM [PSE_FactSubmission];
Hi Andrew - against AdvWrks I've got the following running without any errors. I needed to change Member_Key to MemberValue:
WITH
SET [~COLUMNS] AS
[Product].[Product Categories].[Product]
MEMBER [Measures].[orderMeas] AS
[Date].[Calendar].CurrentMember.MemberValue
SET [~ROWS] AS
Order
(
NonEmpty
(
[Date].[Calendar].[Month].MEMBERS
,[Measures].[Internet Sales Amount]
)
,[Measures].[orderMeas]
,ASC
)
SELECT
NON EMPTY
CrossJoin
(
[~COLUMNS]
,{[Measures].[Internet Sales Amount]}
) ON COLUMNS
,NON EMPTY
Tail
(
[~ROWS]
,12
) ON ROWS
FROM [Adventure Works];

MDX filter data

WITH
MEMBER [Measures].[ParameterCaption] AS [Estate].[Week].CURRENTMEMBER.MEMBER_CAPTION
MEMBER [Measures].[ParameterValue] AS [Estate].[Week].CURRENTMEMBER.UNIQUENAME
MEMBER [Measures].[ParameterLevel] AS [Estate].[Week].CURRENTMEMBER.LEVEL.ORDINAL
SELECT
{[Measures].[ParameterCaption], [Measures].[ParameterValue], [Measures].[ParameterLevel]} ON COLUMNS
,
NON EMPTY (
ORDER (
EXCEPT( [Estate].[Week].[ALL].CHILDREN
, { [Estate].[Week]})
, ( [Estate].[Week].MEMBERVALUE)
, ASC
)
) ON ROWS
From [EstateRpt]
WHERE Filter([V Estate Weekly Rpt].[Week].CHILDREN, [V Estate Weekly Rpt].[Week].MEMBERVALUE = 'NONE')
Hi, i am new to the MDX. I want to filter the week which is not equal to "NONE"? by default, week is set the "NONE", so it will appear the NONE data in cube. I want to filter this NONE.
I do try the WHERE clause but it show the error to me which i do not figure out what is the problem
If you want to filter out 'NONE' then you need to use this in your filter:
<> 'NONE'
Also you need to use CurrentMember within your filter like this example:
SELECT
{
[Date].[Calendar].[Month].&[2006]&[7]
,[Date].[Calendar].[Date].&[20050220]
}
*
{[Measures].[Reseller Sales Amount]} ON COLUMNS
,
{[Product].[Category].Children}
*
{[Geography].[Geography].[Country].MEMBERS} ON ROWS
FROM [Adventure Works]
WHERE
Filter
(
[Geography].[State-Province].MEMBERS
,
[Geography].[State-Province].CurrentMember.Member_Caption <> 'California'
);

MDX Sorting On Columns

Hi,
I want to order the PriceValues field in the following query in Ascending Order
SELECT
NON EMPTY
Hierarchize
(
Union
(
{[PriceValues].[Grand Total]}
,[PriceValues].[Grand Total].Children
)
) ON COLUMNS
,NON EMPTY
Hierarchize
(
Union
(
{[Offer].[Grand Total]}
,[Offer].[Grand Total].Children
)
) ON ROWS
FROM [Act_RenewDetails]
WHERE
{[Measures].[Revenue]};
To order a measure in ascending numerical order:
{ORDER({[PriceValues].[Grand Total],[PriceValues].[Grand Total].Children}, [Measures].[Revenue], BASC)} ON COLUMNS
Edit: Or you can order alphabetically by the member names of a dimension:
{ORDER({[PriceValues].[Grand Total],[PriceValues].[Grand Total].Children}, [PriceValues].CurrentMember.name, BASC)} ON COLUMNS
(I think .name might be .memberName or even .caption - my memory is rusty.)

need to get sum of all members of a dimension minus one member

I am trying to make an MDX query that can tell me how many products were sold in countries other than China. With the following query I can only get the units sold of bottled water for each of the countries, but not their sum. How do I modify the query to get the sum of that ?
SELECT NON EMPTY Except(
{[Location].[All Places].Children},
{[Location].[China]}
) ON COLUMNS,
{[Product].[All Products].[Bottled Water].Children} ON ROWS
FROM [Places]
WHERE [Measures].[Units Sold]
The following should do what you want:
WITH
SET [countries] as Except( {[Location].[All Places].Children}, {[Location].[China]} )
MEMBER [measures].[X] as Sum( [countries] , [Measures].[Units Sold] )
SELECT {[Product].[All Products].[Bottled Water].Children} ON ROWS
FROM [Places]
WHERE [measures].[x]