How can I change this MDX query (get from Saiku) so that "anno" (year) and measures are put in the column?
MDX Query:
WITH
SET [~ROWS_Regime Ricovero_Regime Ricovero.Regime Ricovero] AS
{[Regime Ricovero].[Degenza ordinaria]}
SET [~ROWS_Anno_Anno.Anno] AS
{[Anno].[Anno].MEMBERS}
SELECT
NON EMPTY
{
[Measures].[Numero di Ricoveri]
,[Measures].[Dimessi 0-1 Giorno]
,[Measures].[Dimessi > di 1 Giorno]
,[Measures].[Giornate di Degenza]
,[Measures].[Degenza Media]
,[Measures].[Occupazione Media (Percentuale)]
,[Measures].[Indice di Rotazione]
,[Measures].[Presenti Medi Giornaliari]
,[Measures].[Numero di Interventi]
,[Measures].[DRG Peso]
} ON COLUMNS
,NON EMPTY
NonEmptyCrossJoin
(
[~ROWS_Regime Ricovero_Regime Ricovero.Regime Ricovero]
,[~ROWS_Anno_Anno.Anno]
) ON ROWS
FROM [Cubo Virtuale Report Dati Attività ];
Table
In practice, I would like to see this table vertically and not horizontally.
Thank you in advance
You can swap ROWS and COLUMNS however you like.
This configuration should be more vertical:
WITH
SET [~ROWS_Regime Ricovero_Regime Ricovero.Regime Ricovero] AS
{[Regime Ricovero].[Degenza ordinaria]}
SET [~ROWS_Anno_Anno.Anno] AS
{[Anno].[Anno].MEMBERS}
SELECT
NON EMPTY
[~ROWS_Anno_Anno.Anno]
ON COLUMNS
,NON EMPTY
CrossJoin(
[~ROWS_Regime Ricovero_Regime Ricovero.Regime Ricovero]
,
{
[Measures].[Numero di Ricoveri]
,[Measures].[Dimessi 0-1 Giorno]
,[Measures].[Dimessi > di 1 Giorno]
,[Measures].[Giornate di Degenza]
,[Measures].[Degenza Media]
,[Measures].[Occupazione Media (Percentuale)]
,[Measures].[Indice di Rotazione]
,[Measures].[Presenti Medi Giornaliari]
,[Measures].[Numero di Interventi]
,[Measures].[DRG Peso]
}
)
ON ROWS
FROM [Cubo Virtuale Report Dati Attività ];
Related
I have a CustomerToFactor as a Measure and Customer as a Dimension. Now I want to create a MDX code like this SQL code but I can't. because (WITH) statements has another meaning in MDX.
with Total_Customer(
select cus_id
,sum(ctf_price) cus_total_price
from dbo.Customer
join dbo.CustomertoFactor on cus_id = ctf_cus_id
group by cus_id
)
select cus_id
,cus_name
,ctf_date
,ctf_price
,(cus_total_price / 100 * ctf_price) as Price_pro_customer
from dbo.Customer
join dbo.CustomertoFactor on cus_id = ctf_cus_id
join Total_Customer on Total_customer.cus_id = dbo.Customer.cus_id
SELECT NON EMPTY { [Measures].[ctf_date]
,[Measures].[ctf_price]
, (?) Price_pro_customer
} ON COLUMNS
,NON EMPTY {[Customer].[Customer - cus_name].[Customer - cus_name].ALLMEMBERS}
FROM [CustomerToFactor]
Thanks for your Answers. but it doesn't work. Actually I want it to be grouped for every name you name. for Example: for the name Alex only the sum would have to be calculated for Alex(100+300 = 400) as well as Group by.
I do not really understand the point of the calculation :)
But anyway, in MDX you can have your own measures calculated like this:
WITH MEMBER [Measures].[Price_pro_customer] AS
(SUM([Measures].[ctf_price]) / 100 * [Measures].[ctf_price])
SELECT NON EMPTY { [Measures].[ctf_date]
,[Measures].[ctf_price]
,[Measures].[Price_pro_customer]
} ON COLUMNS
,NON EMPTY {[Customer].[Customer - cus_name].[Customer - cus_name].ALLMEMBERS}
FROM [CustomerToFactor]
I am not sure you'll get the same result as the SQL query though, since you have [Customer].[Customer - cus_name].[Customer - cus_name].ALLMEMBERS on the rows which basically does a GROUP BY on the customer name.
So if in the table you had several rows for the same customer the output of MDX query should be 1 row for each customer. The SUM([Measures].[ctf_price]) is also different since it sums over all customers
I think you should create a date dimension reference to ctf_date.
Then your mdx should be as below:
WITH MEMBER [Measures].[Price_pro_customer] AS
SUM([DimDate].[ctf_date].[All], [Measures].[ctf_price]) / 100 * [Measures].[ctf_price]
SELECT NON EMPTY {
[Measures].[ctf_price] ,
[Measures].[Price_pro_customer]
} ON COLUMNS ,
NON EMPTY {[Customer].[Customer - cus_name].[Customer - cus_name].ALLMEMBERS *
[DimDate].[ctf_date].[ctf_date].ALLMEMBERS} ON ROWS
FROM [CustomerToFactor]
I have a datacube with a dimension of a large number of academic courses. I would like to group the courses (create a set) by the name of the course (using filter and Inst), so that I can calculate some aggregate statistics. i.e. I would ultimately like a list of the number of people doing courses with those groupings (split later by their home geography).
I have four measures, which include
[Measures].[Achievements]
[Measures].[Starts]
[Measures].[Enrolments]
[Measures].[Leavers]
I have managed to make two sets:
CREATE SET [MyDataCube].[BA] AS
{FILTER(
[Aim].[Aim Title].[Aim Title].Members,
(InStr(1, [Aim].[Aim Title].CurrentMember.NAME, "BA ") <> 0)
)
}
GO
CREATE SET [MyDataCube].[BSc] AS
{FILTER(
[Aim].[Aim Title].[Aim Title].Members,
(InStr(1, [Aim].[Aim Title].CurrentMember.NAME, "BSc") <> 0)
)
}
And then I can query a single set:
SELECT
NON EMPTY [AccessCourses] DIMENSION PROPERTIES MEMBER_NAME ON ROWS,
NON EMPTY Hierarchize({DrilldownLevel({[Geography - Learner Home].[Learner Home].[All]})}) DIMENSION PROPERTIES MEMBER_NAME ON COLUMNS
FROM [MyDataCube]
But how can I get a table with [Geography - Learner Home].[Learner Home].[All] on the rows, with a sum of all [Bsc] and [BA] courses on the columns, like:
I would like to do this for [Measures].[Starts].
Something like the following maybe:
WITH
MEMBER [Aim].[Aim Title].[All].[BA] AS
AGGREGATE(
[BA]
)
MEMBER [Aim].[Aim Title].[All].[BSc] AS
AGGREGATE(
[BSc]
)
SELECT
NON EMPTY
[Geography - Learner Home].[Learner Home].MEMBERS ON ROWS,
NON EMPTY
{
[Aim].[Aim Title].[All].[BA]
,[Aim].[Aim Title].[All].[BSc]
} ON COLUMNS
FROM [MyDataCube]
WHERE [Measures].[Starts];
I work on a problem with an MDX Query.
The cube contains models and serials (units) and should show all units in warranty for each year.
This is the a cube with this Dimensions/Measures:
CubeOverview
Now I would select all Serials which are in warranty for a special year.
The problem is that the whole Table v Dim Unit Model 4IB Test contains more than 50 Mio rows which results alsways to an QueryTimeout or sometimes to an MemoryException.
At the moment I have a MDX query (see below) which works if I select special model. But I need the filter to all models.
WITH
MEMBER [Measures].[QtyTotal] AS
[Measures].[QtyInWarranty] + [Measures].[QtyInExtension]
SELECT
NON EMPTY
{
[Measures].[QtyStdOut] ,[Measures].[QtyInExtension] ,[Measures].[QtyStdIn]
,[Measures].[QtyInWarranty] ,[Measures].[QtyTotal] ,[Measures].[SumStartWarranty]
} ON COLUMNS
,NON EMPTY
{
crossjoin(
[v Dim Unit Model 4IB Test].[ModelUnitMapping].[Id Unit].Members
,[Dim Country].[Id Country].[Id Country].members
,[Dim Calendar].[Calendar].[Month Name4report].members
)
} ON ROWS
FROM
(
SELECT
{
[v Dim Unit Model 4IB Test].[model no short].[Model No Short].&[SampleModel]
} ON COLUMNS
FROM
(
SELECT
{
[Dim Calendar].[Calendar].[Year].&[2015]
} ON COLUMNS
FROM [InstalledBaseCS_Serial]
)
)
Does anybody knows a tip to update the query to get all units for one year (round about 4 Mio rows)?
If you're trying to return the results to a visible grid in MDXstudio or SSMS then it may be timing out because there is quite a bit to render.
If you use OPENQUERY or the CLR OLAP Extensions then try the following:
Do not return the results to the screen but INSERT results into a table.
Simplifiy your script by taking away the custom measure. This can easily be calculated later as it is trivial: I have a feeling it is slowing down ssas.
Script
SELECT
NON EMPTY
{
[Measures].[QtyStdOut]
,[Measures].[QtyInExtension]
,[Measures].[QtyStdIn]
,[Measures].[QtyInWarranty]
,[Measures].[SumStartWarranty]
} ON 0
,NON EMPTY
[v Dim Unit Model 4IB Test].[ModelUnitMapping].[Id Unit].Members
*[Dim Country].[Id Country].[Id Country].members
*[Dim Calendar].[Calendar].[Month Name4report].members
ON 1
FROM
(
SELECT
[v Dim Unit Model 4IB Test].[model no short].[Model No Short].&[SampleModel] ON 0
FROM
(
SELECT [Dim Calendar].[Calendar].[Year].&[2015] ON 0
FROM [InstalledBaseCS_Serial]
)
);
I have a hierarchy with 5 level,I use Descendants() to retrieve all lower level of a member.But i end up with a one column result where i like to have a result with one column for each level.So on each row i repeat the parent,grand parents etc of the current member.
WITH
MEMBER [Measures].[key] AS
[DimGLAcct].[MgtCOA].CurrentMember.UNIQUENAME
MEMBER [Measures].[level_] AS
[DimGLAcct].[MgtCOA].CurrentMember.level.ordinal
SELECT
{
[Measures].[key]
, [Measures].[level_]
, [Measures].[Actuals]
} ON COLUMNS,
{
Descendants(
[DimGLAcct].[MgtCOA].[Mparent5].&[MCOA].&[400000M - Total operating overhead expenses].&[440000M - Other expenses].&[441000M - Other expenses]
,
,SELF_AND_AFTER
)
} ON ROWS
FROM [Model];
I cannot quite suss out the names of your levels but it is ok to do the following in mdx:
WITH
MEMBER [Measures].[key] AS
[DimGLAcct].[MgtCOA].CurrentMember.UNIQUENAME
MEMBER [Measures].[level_] AS
[DimGLAcct].[MgtCOA].CurrentMember.level.ordinal
SELECT
{
[Measures].[key]
, [Measures].[level_]
, [Measures].[Actuals]
} ON COLUMNS,
[DimGLAcct].[LevelX]
*[DimGLAcct].[LevelY]
*[DimGLAcct].[LevelZ]
*[DimGLAcct].[LevelK]
ON ROWS
FROM [Model];
Each of the levels in your user hierarchy will have respective attribute hieraries - which are used in the above.
I'm using the following but i think there's probably a much simpler method of excluding the All members from the results?
WITH
SET [Non_All_Distributors] AS
{FILTER(
[Distributor Name].members,
(InStr(1, [Distributor Name].CurrentMember.NAME, "All") = 0)
)}
SET [Non_All_Countries] AS
{FILTER(
[Geography Country].members,
(InStr(1, [Geography Country].CurrentMember.NAME, "All") = 0)
)}
SELECT
NON EMPTY
[Dimension].[Hierarchy].DEFAULTMEMBER
ON COLUMNS,
NON EMPTY
[Non_All_Distributors]
*
[Non_All_Countries]
*
Tail([Date].[Date - Calendar Month].[Calendar Day].Members,60)
*
{
[Measures].[Revenue],
[Measures].[NumClients]
}
ON ROWS
FROM [OURCUBE]
Just use
SELECT
NON EMPTY
[Dimension].[Hierarchy].DEFAULTMEMBER
ON COLUMNS,
NON EMPTY
[dimension of Distributor Name].[Distributor Name].[Distributor Name].Members
*
[dimension of Geography Country].[Geography Country].[Geography Country].Members
*
Tail([Date].[Date - Calendar Month].[Calendar Day].Members,60)
*
{
[Measures].[Revenue],
[Measures].[NumClients]
}
ON ROWS
FROM [OURCUBE]
There is no need to define sets here. you can directly state the distributor and country members in the rows clause.
By repeating the attribute name, you restrict the attribute hierarchy - which you refer to by [dim].[attrib name] to the level below the All member, which happens to have the same name as the attribute again. An attribute hierarchy has two levels: level 0 contains the 'All' member and level 1 all the members of the attribute. (This is true only if you did not do special configurations like setting the attribute as non aggregateabable, but I assume the standard case, as you have All members in your hierarchies.
Apart from being more simple, this statement will run much faster, as Filter is a real performance killer in many cases.
I would use the Descendants function and the AFTER option as following; this way you get all the members of the hierarchy below the all member:
select
[Measures].[Amount] on 0,
Descendants([Customers].[Geography].[All], 1, AFTER ) on 1
from [Sales]
(edited: with a request working with MSAS Adv. Works : removed the distance param)
select
Measures].[Order Count] on 0,
Descendants( [Geography].[Geography].[All], , AFTER ) on 1
from [Adventure Works]