MDX Calculated Dimension Member base on another dimension - ssas

There are two dimensions
[record].[record id]
[product].[product name]
[measures].[sales]
I want to create a new dimension attribute, in the record dimension.
with member [record].[derived record id] as iif([product].[product name].[product name]
in ('pen', 'eraser', 'notepad'), 0, [record].[record id].[record id])
select [measures].[sales] on 0,
[record].[derived record id].[derived record id] on 1
You see what I am trying to do is to combine some the the rows where product name is in a select list and leave the rest as is. I can do this during the load process to create this new attribute, but how do I do it in MDX?
Thanks in advance.

As far as I understand, you want to have a calculated member of the [record].[record id] hierarchy that delivers the value 0 for all measures in the cube in case the current product name member is one of 'pen', 'eraser', and 'notepad'. To achieve this, you can use the following MDX:
with member [record].[record id].[derived record id] -- note: you must name the hierarchy for calculated members
as
IIf([product].[product name].CurrentMember IS [product].[product name].[pen]
or
[product].[product name].CurrentMember IS [product].[product name].[eraser]
or
[product].[product name].CurrentMember IS [product].[product name].[notepad]
,
0
,
Measures.CurrentMember
)
select [measures].[sales]
on 0,
[record].[record id].[derived record id]
on 1
from [YourCube]

Related

Multiply Dimension item with the numeric values

I have Dimension column as Price and the Measure column as Quantity, I want to multiply price with the quantity,Please help me write MDX.
I tried with the below query.
With Member [Measures].[A] As ([Part ID].[Price]), Format_String ='Number'
Member [Measures].[B] As [Measures].[Quantity] * [Measures].[A]
Select {[Measures].[A],[Measures].[B]} On Columns, NON EMPTY( [Part ID].[Part Id].Children ) On Rows from [studio_bomdata]
You just need the following change
With Member [Measures].[A] As ([Part ID].[Price].CurrentMember.Properties ("Member_Value",TYPED)
)

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];

List all dimension members filtering on dimension attribute value

I want to list out all cars from Dimension.Car which has a status IsPremium = 1 from cube.
And also, a separate list of all cars from Dimension.Car which has status IsFourWeeler = 1
Dimension has attributes as follows:
1. Car Code
2. Car Name
3. IsPremium
4. IsFourWheeler
If they are different hierachies (either attribute or user hierarchies) in the same dimension then you can use the function EXISTS.
Defined here: https://msdn.microsoft.com/en-us/library/ms144936.aspx?f=255&MSPPError=-2147217396
The example they show is the same as your situation:
SELECT
[Measures].[Internet Sales Amount] ON 0,
EXISTS(
[Customer].[Customer].[Customer].MEMBERS
, {[Customer].[State-Province].&[CA]&[US]}
) ON 1
FROM [Adventure Works];
But you have
SELECT
[Measures].[SomeMeasuresInCube] ON 0,
EXISTS(
[Dimension.Car].[Car].MEMBERS
, [[Dimension.Car]].[IsPremium].[1]
) ON 1
FROM [YourCube];
NonEmpty could also be your friend:
WITH SET [SpecialCars] AS
NONEMPTY(
[Dimension.Car].[Car].MEMBERS
,([[Dimension.Car]].[IsFourWheeler].[1])
)
SELECT
[Measures].[SomeMeasuresInCube] ON 0,
[SpecialCars] ON 1
FROM [YourCube];

MDX: I need column count based on the total rows

Here we have total 14 rows, I need one more column (RowCount-Column name)
every-cell contains 14 (reputation) means total row counts.
below is the query
WITH MEMBER DimName AS [DimClinic].[Provider Key].CurrentMember.Member_Caption
MEMBER DimKey AS [DimClinic].[Provider Key].CurrentMember.Member_Key
SELECT {[Measures].DimKey ,
[Measures].DimName ,
[Measures].[DrPatientKeyCnt]} ON COLUMNS ,
NonEmpty([DimClinic].[Provider Key].[Provider Key])ON ROWS
FROM [PopulationReportCube]
WITH
MEMBER DimName AS
[DimClinic].[Provider Key].CurrentMember.Member_Caption
MEMBER DimKey AS
[DimClinic].[Provider Key].CurrentMember.Member_Key
MEMBER RowCount AS
Count
(
NonEmpty
(
[DimClinic].[Provider Key].[Provider Key]
,[Measures].[DrPatientKeyCnt]
)
)
SELECT
{
[Measures].DimKey
,[Measures].DimName
,[Measures].[DrPatientKeyCnt]
,[Measures].[RowCount]
} ON COLUMNS
,NonEmpty([DimClinic].[Provider Key].[Provider Key]) ON ROWS
FROM [PopulationReportCube];

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]